diff --git a/ChangeLog b/ChangeLog
index 00a99cef973..fd55afae09e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -64,6 +64,7 @@ For users:
- New: Can choose contact on event (action com) creation, and filtred by thirdparty.
- New: Add hidden option MAIN_FORCE_DEFAULT_STATE_ID.
- New: Add page to make mass stock movement.
+- New: Add field oustanding limit into thirdparty properties.
For translators:
- Qual: Normalized sort order of all languages files with english reference files.
diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php
index 1189b77ec57..8574e6eb5ad 100644
--- a/htdocs/comm/fiche.php
+++ b/htdocs/comm/fiche.php
@@ -128,6 +128,14 @@ if ($action == 'cstc')
if ($result < 0) setEventMessage($object->error,'errors');
}
+// Update communication level
+if ($action == 'setOutstandingBill')
+{
+ $object->fetch($id);
+ $object->outstanding_limit=GETPOST('OutstandingBill');
+ $result=$object->set_OutstandingBill($user);
+ if ($result < 0) setEventMessage($object->error,'errors');
+}
/*
@@ -369,6 +377,18 @@ if ($id > 0)
print '';
print '';
+ if ($object->client)
+ {
+ print '
';
+ print '| ';
+ print $form->editfieldkey("OutstandingBill",'OutstandingBill',$object->outstanding_limit,$object,$user->rights->societe->creer);
+ print ' | ';
+ print $form->editfieldval("OutstandingBill",'OutstandingBill',$object->outstanding_limit,$object,$user->rights->societe->creer);
+ print ' | ';
+ print '
';
+ }
+
+
// Multiprice level
if (! empty($conf->global->PRODUIT_MULTIPRICES))
{
@@ -898,4 +918,4 @@ dol_htmloutput_mesg('',$mesgs);
// End of page
llxFooter();
$db->close();
-?>
\ No newline at end of file
+?>
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index f6d082c763d..c56688b3e44 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1885,6 +1885,18 @@ else
print '';
}
+ if ($soc->outstanding_limit)
+ {
+ // Outstanding Bill
+ print '| ';
+ print $langs->trans('OutstandingBill');
+ print ' | ';
+ print price($soc->get_OutstandingBill()).' / ';
+ print price($soc->outstanding_limit, 0, '', 1, -1, -1, $conf->currency);
+ print ' | ';
+ print '
';
+ }
+
// Other attributes
$res=$object->fetch_optionals($object->id,$extralabels);
$parameters=array('colspan' => ' colspan="3"');
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 3016f5ac191..737e31cca7f 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -2195,6 +2195,19 @@ else
print '';
}
+
+ if ($soc->outstanding_limit)
+ {
+ // Outstanding Bill
+ print '| ';
+ print $langs->trans('OutstandingBill');
+ print ' | ';
+ print price($soc->get_OutstandingBill()).' / ';
+ print price($soc->outstanding_limit, 0, '', 1, -1, -1, $conf->currency);
+ print ' | ';
+ print '
';
+ }
+
// Other attributes
$res=$object->fetch_optionals($object->id,$extralabels);
$parameters=array('colspan' => ' colspan="3"');
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 31c69d93295..a2c9dc80594 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -2318,6 +2318,18 @@ if ($action == 'create')
print '';
}
+ if ($soc->outstanding_limit)
+ {
+ // Outstanding Bill
+ print '| ';
+ print $langs->trans('OutstandingBill');
+ print ' | ';
+ print price($soc->get_OutstandingBill()).' / ';
+ print price($soc->outstanding_limit).' | ';
+ print ' | ';
+ print '
';
+ }
+
// Other attributes
$parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
@@ -3034,6 +3046,7 @@ else if ($id > 0 || ! empty($ref))
$nbrows=8; $nbcols=2;
if (! empty($conf->projet->enabled)) $nbrows++;
if (! empty($conf->banque->enabled)) $nbcols++;
+ if (! empty($soc->outstandingbill)) $nbrows++;
if($mysoc->localtax1_assuj=="1") $nbrows++;
if($mysoc->localtax2_assuj=="1") $nbrows++;
if ($selleruserevenustamp) $nbrows++;
@@ -3305,6 +3318,18 @@ else if ($id > 0 || ! empty($ref))
}
print '';
+ if ($soc->outstandingbill)
+ {
+ // Outstanding Bill
+ print '| ';
+ print $langs->trans('OutstandingBill');
+ print ' | ';
+ print price($soc->get_OutstandingBill()).' / ';
+ print price($soc->outstandingbill);
+ print ' | ';
+ print '
';
+ }
+
// Amount
print '| '.$langs->trans('AmountHT').' | ';
print ''.price($object->total_ht,1,'',1,-1,-1,$conf->currency).' |
';
@@ -3955,4 +3980,4 @@ dol_htmloutput_mesg('',$mesgs);
llxFooter();
$db->close();
-?>
\ No newline at end of file
+?>
diff --git a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql
index f6b7abcf9f8..889e606c4fe 100755
--- a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql
+++ b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql
@@ -299,7 +299,8 @@ ALTER TABLE llx_facture_fourn MODIFY COLUMN fk_mode_reglement integer NULL;
ALTER TABLE llx_facture_fourn MODIFY COLUMN fk_cond_reglement integer NULL;
-insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (9,'COMPANY_SENTBYMAIL','Mails sent from third party card','Executed when you send email from third party card','societe',1);
+INSERT INTO llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (9,'COMPANY_SENTBYMAIL','Mails sent from third party card','Executed when you send email from third party card','societe',1);
+
ALTER TABLE llx_contratdet ADD column product_type integer DEFAULT 1 after total_ttc;
@@ -311,3 +312,7 @@ create table llx_contrat_extrafields
import_key varchar(14) -- import key
) ENGINE=innodb;
+
+-- add outstanding bill
+ALTER TABLE llx_societe ADD outstanding_limit double(24,8) DEFAULT NULL AFTER mode_reglement_supplier;
+
diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql
index 9348ab3b6d5..e0588f04794 100644
--- a/htdocs/install/mysql/tables/llx_societe.sql
+++ b/htdocs/install/mysql/tables/llx_societe.sql
@@ -52,7 +52,7 @@ create table llx_societe
fk_effectif integer DEFAULT 0, --
fk_typent integer DEFAULT 0, --
fk_forme_juridique integer DEFAULT 0, -- juridical status
- fk_currency integer DEFAULT 0, -- currency
+ fk_currency integer DEFAULT 0, -- currency
siren varchar(128), -- IDProf1: siren or RCS for france
siret varchar(128), -- IDProf2: siret for france
ape varchar(128), -- IDProf3: code ape for france
@@ -61,7 +61,7 @@ create table llx_societe
idprof6 varchar(128), -- IDProf6: nu for france
tva_intra varchar(20), -- tva
capital real, -- capital de la societe
- fk_stcomm integer DEFAULT 0 NOT NULL, -- commercial statut
+ fk_stcomm integer DEFAULT 0 NOT NULL, -- commercial statut
note_private text, --
note_public text, --
prefix_comm varchar(5), -- prefix commercial
@@ -85,6 +85,7 @@ create table llx_societe
barcode varchar(255), -- barcode
fk_barcode_type integer NULL DEFAULT 0, -- barcode type
price_level integer NULL, -- level of price for multiprices
+ outstanding_limit double(24,8) DEFAULT NULL, -- allowed outstanding limit
default_lang varchar(6), -- default language
logo varchar(255),
canvas varchar(32), -- type of canvas if used (null by default)
diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang
index 6942dfea6ee..d218e1bc41b 100644
--- a/htdocs/langs/en_US/companies.lang
+++ b/htdocs/langs/en_US/companies.lang
@@ -397,7 +397,7 @@ InActivity=Open
ActivityCeased=Closed
ActivityStateFilter=Activity status
ProductsIntoElements=List of products into
-
+OutstandingBill=Outstanding Bill
# Monkey
MonkeyNumRefModelDesc=Return numero with format %syymm-nnnn for customer code and %syymm-nnnn for supplier code where yy is year, mm is month and nnnn is a sequence with no break and no return to 0.
# Leopard
diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang
index 2d9d58b3b8f..70964d32950 100644
--- a/htdocs/langs/fr_FR/companies.lang
+++ b/htdocs/langs/fr_FR/companies.lang
@@ -397,7 +397,7 @@ InActivity=En activité
ActivityCeased=Clos
ActivityStateFilter=Statut d'activité
ProductsIntoElements=Liste des produits dans les %s
-
+OutstandingBill=Encours de facturation
# Monkey
MonkeyNumRefModelDesc=Renvoie le numéro sous la forme %syymm-nnnn pour les codes clients et %syymm-nnnn pour les codes fournisseurs où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0.
# Leopard
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 154a7e344f2..162550a162b 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -124,6 +124,7 @@ class Societe extends CommonObject
var $statut_commercial;
var $price_level;
+ var $outstanding_limit;
var $datec;
var $date_update;
@@ -707,7 +708,7 @@ class Societe extends CommonObject
$sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
$sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj';
$sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax2_assuj, s.fk_prospectlevel, s.default_lang, s.logo';
- $sql .= ', s.import_key, s.canvas';
+ $sql .= ', s.outstanding_limit, s.import_key, s.canvas';
$sql .= ', fj.libelle as forme_juridique';
$sql .= ', e.libelle as effectif';
$sql .= ', p.code as country_code, p.libelle as country';
@@ -836,6 +837,8 @@ class Societe extends CommonObject
$this->default_lang = $obj->default_lang;
$this->logo = $obj->logo;
+ $this->outstanding_limit = $obj->outstanding_limit;
+
// multiprix
$this->price_level = $obj->price_level;
@@ -2767,6 +2770,71 @@ class Societe extends CommonObject
}
}
+ /**
+ * Set outstanding value
+ *
+ * @param User $user User making change
+ * @return int <0 if KO, >0 if OK
+ */
+ function set_outstanding($user)
+ {
+ if ($this->id)
+ {
+ $this->db->begin();
+
+ $now=dol_now();
+
+ $outstanding = price2num($this->outstanding_limit);
+
+ // Positionne l'encours de facturaiton
+ $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
+ $sql.= " outstanding_limit=".$outstanding;
+ $sql.= " WHERE rowid = ".$this->id;
+
+ dol_syslog(get_class($this)."::set_outstanding sql=".$sql);
+ $resql=$this->db->query($sql);
+ if (! $resql)
+ {
+ $this->db->rollback();
+ $this->error=$this->db->error();
+ return -1;
+ }
+
+ $this->db->commit();
+ return 1;
+ }
+ }
+
+ /**
+ * return amount of bill not paid
+ *
+ * @return boolean Yes or no
+ */
+ function get_OutstandingBill()
+ {
+ /* Accurate value of remain to pay is to sum remaintopay for each invoice
+ $paiement = $invoice->getSommePaiement();
+ $creditnotes=$invoice->getSumCreditNotesUsed();
+ $deposits=$invoice->getSumDepositsUsed();
+ $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
+ $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
+ */
+ $sql = "SELECT sum(total) as amount FROM ".MAIN_DB_PREFIX."facture as f";
+ $sql .= " WHERE fk_soc = ". $this->id;
+ $sql .= " AND paye = 0";
+ $sql .= " AND fk_statut <> 0";
+
+ dol_syslog("get_OutstandingBill sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $obj=$this->db->fetch_object($resql);
+ return ($obj->amount);
+ }
+ else
+ return 0;
+ }
+
/**
* Return label of status customer is prospect/customer
*