diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index f4a634aad6c..7cf7b372a53 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -35,8 +35,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
-require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
+require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
if (! empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
@@ -951,6 +952,94 @@ if ($id > 0)
}
}
+ /*
+ * Last invoices templates
+ */
+ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
+ {
+ $invoicetemplate = new FactureRec($db);
+
+ $sql = 'SELECT f.rowid as id, f.titre as ref, f.amount';
+ $sql.= ', f.total as total_ht';
+ $sql.= ', f.tva as total_tva';
+ $sql.= ', f.total_ttc';
+ $sql.= ', f.datec as dc';
+ $sql.= ', f.status as status';
+ $sql.= ', s.nom, s.rowid as socid';
+ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
+ $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
+ $sql.= " AND f.entity = ".$conf->entity;
+ $sql.= ' GROUP BY f.rowid, f.titre, f.amount, f.total, f.tva, f.total_ttc,';
+ $sql.= ' f.datec,';
+ $sql.= ' f.status,';
+ $sql.= ' s.nom, s.rowid';
+ $sql.= " ORDER BY f.datec DESC";
+
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $var=true;
+ $num = $db->num_rows($resql);
+ $i = 0;
+ if ($num > 0)
+ {
+ print '
';
+
+ print '';
+ print ' | ';
+ print '
';
+ }
+
+ while ($i < $num && $i < $MAXLIST)
+ {
+ $objp = $db->fetch_object($resql);
+
+ print '';
+ print '| ';
+ $invoicetemplate->id = $objp->id;
+ $invoicetemplate->ref = $objp->ref;
+ $invoicetemplate->statut = $objp->status;
+ $invoicetemplate->total_ht = $objp->total_ht;
+ $invoicetemplate->total_tva = $objp->total_tva;
+ $invoicetemplate->total_ttc = $objp->total_ttc;
+ print $invoicetemplate->getNomUrl(1);
+ print ' | ';
+ if ($objp->dc > 0)
+ {
+ print ''.dol_print_date($db->jdate($objp->dc),'day').' | ';
+ }
+ else
+ {
+ print '!!! | ';
+ }
+ print '';
+ print price($objp->total_ht);
+ print ' | ';
+
+ if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
+ {
+ print '';
+ print price($objp->total_ttc);
+ print ' | ';
+ }
+
+ print '';
+ print ($invoicetemplate->LibStatut(0,$invoicetemplate->statut,5,0));
+ print ' | ';
+ print "
\n";
+ $i++;
+ }
+ $db->free($resql);
+
+ if ($num > 0) print "
";
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ }
+
/*
* Last invoices
*/
diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php
index 967fdc908bc..f6c2fe7ef2e 100644
--- a/htdocs/compta/facture/class/facture-rec.class.php
+++ b/htdocs/compta/facture/class/facture-rec.class.php
@@ -248,7 +248,7 @@ class FactureRec extends CommonInvoice
*/
function fetch($rowid, $ref='', $ref_ext='', $ref_int='')
{
- $sql = 'SELECT f.rowid, f.entity, f.titre, f.fk_soc, f.amount, f.tva, f.localtax1, f.localtax2, f.total, f.total_ttc';
+ $sql = 'SELECT f.rowid, f.entity, f.titre, f.status, f.fk_soc, f.amount, f.tva, f.localtax1, f.localtax2, f.total, f.total_ttc';
$sql.= ', f.remise_percent, f.remise_absolue, f.remise';
$sql.= ', f.date_lim_reglement as dlr';
$sql.= ', f.note_private, f.note_public, f.fk_user_author';
@@ -281,6 +281,7 @@ class FactureRec extends CommonInvoice
$this->titre = $obj->titre;
$this->ref = $obj->titre;
$this->ref_client = $obj->ref_client;
+ $this->statut = $obj->status;
$this->type = $obj->type;
$this->datep = $obj->dp;
$this->date = $obj->df;
@@ -297,7 +298,6 @@ class FactureRec extends CommonInvoice
$this->close_code = $obj->close_code;
$this->close_note = $obj->close_note;
$this->socid = $obj->fk_soc;
- $this->statut = $obj->fk_statut;
$this->date_lim_reglement = $this->db->jdate($obj->dlr);
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
@@ -956,6 +956,59 @@ class FactureRec extends CommonInvoice
return $result;
}
+ /**
+ * Renvoi le libelle d'un statut donne
+ *
+ * @param int $paye Status field paye
+ * @param int $status Id status
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=long label + picto
+ * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
+ * @param int $type Type invoice
+ * @return string Libelle du statut
+ */
+ function LibStatut($paye,$status,$mode=0,$alreadypaid=-1,$type=0)
+ {
+ global $langs;
+ $langs->load('bills');
+
+ //print "$paye,$status,$mode,$alreadypaid,$type";
+ if ($mode == 0)
+ {
+ $prefix='';
+ if ($type == -1) return $langs->trans('Suspended'); // credit note
+ else return $langs->trans('Active');
+ }
+ if ($mode == 1)
+ {
+ $prefix='Short';
+ if ($status == -1) return $langs->trans('Suspended');
+ else return $langs->trans('Active');
+ }
+ if ($mode == 2)
+ {
+ if ($status == -1) return img_picto($langs->trans('Suspended'),'statut6').' '.$langs->trans('Suspended');
+ else return img_picto($langs->trans('Active'),'statut4').' '.$langs->trans('Active');
+ }
+ if ($mode == 3)
+ {
+ $prefix='Short';
+ if ($type == -1) return img_picto($langs->trans('Suspended'),'statut6');
+ else return img_picto($langs->trans('Active'),'statut4');
+ }
+ if ($mode == 4)
+ {
+ $prefix='';
+ if ($type == -1) return img_picto($langs->trans('Suspended'),'statut6').' '.$langs->trans('Suspended');
+ else return img_picto($langs->trans('Active'),'statut4').' '.$langs->trans('Active');
+ }
+ if ($mode == 5 || $mode == 6)
+ {
+ $prefix='';
+ if ($mode == 5) $prefix='Short';
+ if ($type == -1) return ''.$langs->trans('Suspended').' '.img_picto($langs->trans('Suspended'),'statut6');
+ else return ''.$langs->trans('Active').' '.img_picto($langs->trans('Active'),'statut4');
+ }
+ }
/**
* Initialise an instance with random values.
@@ -1309,7 +1362,7 @@ class FactureLigneRec extends CommonInvoiceLine
*/
function fetch($rowid)
{
- $sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
+ $sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
$sql.= ' l.rang, l.special_code,';
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 8d7e0309a1d..f4b36162f82 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2956,6 +2956,8 @@ abstract class CommonObject
*/
function isObjectUsed($id=0)
{
+ global $langs;
+
if (empty($id)) $id=$this->id;
// Check parameters
@@ -2965,10 +2967,19 @@ abstract class CommonObject
return -1;
}
+ $arraytoscan = $this->childtables;
+ // For backward compatibility, we check if array is old format array('table1', 'table2', ...)
+ $tmparray=array_keys($this->childtables);
+ if (is_numeric($tmparray[0]))
+ {
+ $arraytoscan = array_flip($this->childtables);
+ }
+
// Test if child exists
$haschild=0;
- foreach($this->childtables as $table)
+ foreach($arraytoscan as $table => $elementname)
{
+ //print $id.'-'.$table.'-'.$elementname.'
';
// Check if third party can be deleted
$sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table;
$sql.= " WHERE ".$this->fk_element." = ".$id;
@@ -2976,19 +2987,24 @@ abstract class CommonObject
if ($resql)
{
$obj=$this->db->fetch_object($resql);
- $haschild+=$obj->nb;
- //print 'Found into table '.$table;
- if ($haschild) break; // We found at least on, we stop here
+ if ($obj->nb > 0)
+ {
+ $langs->load("errors");
+ //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild;
+ $haschild += $obj->nb;
+ $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
+ break; // We found at least one, we stop here
+ }
}
else
{
- $this->error=$this->db->lasterror();
+ $this->errors[]=$this->db->lasterror();
return -1;
}
}
if ($haschild > 0)
{
- $this->error="ErrorRecordHasChildren";
+ $this->errors[]="ErrorRecordHasChildren";
return $haschild;
}
else return 0;
diff --git a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
index 5bbe4a56f24..0b67bf4b369 100644
--- a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
+++ b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
@@ -35,6 +35,11 @@ ALTER TABLE llx_product_price ADD COLUMN multicurrency_price_ttc double(24,8) DE
ALTER TABLE llx_website_page ADD COLUMN fk_user_create integer;
ALTER TABLE llx_website_page ADD COLUMN fk_user_modif integer;
+
+-- For 7.0
+
+ALTER TABLE llx_facture_rec ADD COLUMN status integer DEFAULT 1;
+
UPDATE llx_c_email_templates SET position = 0 WHERE position IS NULL;
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1, 'VENTES', 'Income of products/services', 'Exemple: 7xxxxx', 0, 0, '', '10', 1, 1);
diff --git a/htdocs/install/mysql/tables/llx_facture_rec.sql b/htdocs/install/mysql/tables/llx_facture_rec.sql
index e9764e1e575..9258634a1de 100644
--- a/htdocs/install/mysql/tables/llx_facture_rec.sql
+++ b/htdocs/install/mysql/tables/llx_facture_rec.sql
@@ -28,6 +28,8 @@ create table llx_facture_rec
datec datetime, -- date de creation
tms timestamp, -- date creation/modification
+ status integer DEFAULT 1, -- 1=active, 0=suspended
+
amount double(24,8) DEFAULT 0 NOT NULL,
remise real DEFAULT 0,
remise_percent real DEFAULT 0,
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 44cb0143a1e..3ffbcf87080 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -155,9 +155,13 @@ FoundXQualifiedRecurringInvoiceTemplate=Found %s recurring template invoice(s) q
NotARecurringInvoiceTemplate=Not a recurring template invoice
NewBill=New invoice
LastBills=Latest %s invoices
+LatestTemplateInvoices=Latest %s template invoices
+LatestCustomerTemplateInvoices=Latest %s customer template invoices
+LatestSupplierTemplateInvoices=Latest %s supplier template invoices
LastCustomersBills=Latest %s customer invoices
LastSuppliersBills=Latest %s supplier invoices
AllBills=All invoices
+AllCustomerTemplateInvoices=All template invoices
OtherBills=Other invoices
DraftBills=Draft invoices
CustomersDraftInvoices=Customer draft invoices
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index eb4560fb491..003eedeac8a 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -75,6 +75,7 @@ ErrorCantSaveADoneUserWithZeroPercentage=Can't save an action with "statut not s
ErrorRefAlreadyExists=Ref used for creation already exists.
ErrorPleaseTypeBankTransactionReportName=Please type bank statement name where entry is reported (Format YYYYMM or YYYYMMDD)
ErrorRecordHasChildren=Failed to delete record since it has some childs.
+ErrorRecordHasAtLeastOneChildOfType=Object has at least one child of type %s
ErrorRecordIsUsedCantDelete=Can't delete record. It is already used or included into other object.
ErrorModuleRequireJavascript=Javascript must not be disabled to have this feature working. To enable/disable Javascript, go to menu Home->Setup->Display.
ErrorPasswordsMustMatch=Both typed passwords must match each other
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index da9769d748a..2aa35625aa0 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -1977,7 +1977,7 @@ else
print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 200);
}
- dol_htmloutput_errors($error,$errors);
+ dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
$linkback = ''.$langs->trans("BackToList").'';
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 49482b77219..8e210a01c6c 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -43,9 +43,11 @@ class Societe extends CommonObject
public $element='societe';
public $table_element = 'societe';
public $fk_element='fk_soc';
- protected $childtables=array("supplier_proposal","propal","commande","facture","facture_rec","contrat","fichinter","facture_fourn","commande_fournisseur","projet","expedition","prelevement_lignes"); // To test if we can delete object
+ protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord'); // To test if we can delete object
+ protected $childtablesoncascade=array("llx_societe_prices", "llx_societe_log", "llx_societe_address", "llx_product_fournisseur_price", "llx_product_customer_price_log", "llx_product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "llx_categorie", "llx_notify", "llx_notfy_def");
- /**
+
+ /**
* 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
* @var int
*/
@@ -1424,11 +1426,11 @@ class Societe extends CommonObject
// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
if ($this->client || $this->prospect)
{
- $toute_categs ['societe'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
+ $toute_categs['societe'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
}
if ($this->fournisseur)
{
- $toute_categs ['fournisseur'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
+ $toute_categs['fournisseur'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
}
// Remove each "Categorie"
@@ -1441,78 +1443,19 @@ class Societe extends CommonObject
}
}
- // Remove contacts
- if (! $error)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
- $sql.= " WHERE fk_soc = " . $id;
- if (! $this->db->query($sql))
- {
- $error++;
- $this->error .= $this->db->lasterror();
- }
- }
-
- // Update link in member table
- if (! $error)
- {
- $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
- $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
- if (! $this->db->query($sql))
- {
- $error++;
- $this->error .= $this->db->lasterror();
- dol_syslog(get_class($this)."::delete erreur -1 ".$this->error, LOG_ERR);
- }
- }
-
- // Remove ban
- if (! $error)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib";
- $sql.= " WHERE fk_soc = " . $id;
- if (! $this->db->query($sql))
- {
- $error++;
- $this->error = $this->db->lasterror();
- }
- }
-
- // Remove societe_remise
- if (! $error)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise";
- $sql.= " WHERE fk_soc = " . $id;
- if (! $this->db->query($sql))
- {
- $error++;
- $this->error = $this->db->lasterror();
- }
- }
-
- // Remove societe_remise_except
- if (! $error)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except";
- $sql.= " WHERE fk_soc = " . $id;
- if (! $this->db->query($sql))
- {
- $error++;
- $this->error = $this->db->lasterror();
- }
- }
-
- // Remove associated users
- if (! $error)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux";
- $sql.= " WHERE fk_soc = " . $id;
- if (! $this->db->query($sql))
- {
- $error++;
- $this->error = $this->db->lasterror();
- }
- }
+ foreach ($this->childtablesoncascade as $tabletodelete)
+ {
+ if (! $error)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
+ $sql.= " WHERE fk_soc = " . $id;
+ if (! $this->db->query($sql))
+ {
+ $error++;
+ $this->errors[] = $this->db->lasterror();
+ }
+ }
+ }
// Removed extrafields
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
@@ -1530,11 +1473,10 @@ class Societe extends CommonObject
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
$sql.= " WHERE rowid = " . $id;
- dol_syslog(get_class($this)."::delete", LOG_DEBUG);
if (! $this->db->query($sql))
{
$error++;
- $this->error = $this->db->lasterror();
+ $this->errors[] = $this->db->lasterror();
}
}