diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f4645721185..9fb99f69173 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -916,6 +916,7 @@ abstract class CommonObject // TODO uniformize field name $fieldname = 'fk_mode_reglement'; if ($this->element == 'societe') $fieldname = 'mode_reglement'; + if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' SET '.$fieldname.' = '.$id; @@ -955,6 +956,7 @@ abstract class CommonObject // TODO uniformize field name $fieldname = 'fk_cond_reglement'; if ($this->element == 'societe') $fieldname = 'cond_reglement'; + if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' SET '.$fieldname.' = '.$id; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index c0d1635a05f..1376a4384cc 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -943,7 +943,8 @@ class CommandeFournisseur extends CommonOrder $sql.= ", fk_statut"; $sql.= ", source"; $sql.= ", model_pdf"; - //$sql.= ", fk_mode_reglement"; + $sql.= ", fk_mode_reglement"; + $sql.= ", fk_cond_reglement"; $sql.= ") "; $sql.= " VALUES ("; $sql.= "''"; @@ -958,7 +959,8 @@ class CommandeFournisseur extends CommonOrder $sql.= ", 0"; $sql.= ", " . $this->source; $sql.= ", '".$conf->global->COMMANDE_SUPPLIER_ADDON_PDF."'"; - //$sql.= ", ".$this->mode_reglement_id; + $sql.= ", ".$this->mode_reglement_id; + $sql.= ", ".$this->cond_reglement_id; $sql.= ")"; dol_syslog(get_class($this)."::create sql=".$sql); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 1d97c737188..cf514271fd6 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -76,6 +76,10 @@ class FactureFournisseur extends CommonInvoice var $note_private; var $note_public; var $propalid; + var $cond_reglement_id; + var $cond_reglement_code; + var $mode_reglement_id; + var $mode_reglement_code; var $lines; var $fournisseur; // deprecated @@ -143,6 +147,8 @@ class FactureFournisseur extends CommonInvoice $sql.= ", datec"; $sql.= ", datef"; $sql.= ", fk_projet"; + $sql.= ", fk_cond_reglement"; + $sql.= ", fk_mode_reglement"; $sql.= ", note_private"; $sql.= ", note_public"; $sql.= ", fk_user_author"; @@ -157,6 +163,8 @@ class FactureFournisseur extends CommonInvoice $sql.= ", '".$this->db->idate($now)."'"; $sql.= ", '".$this->db->idate($this->date)."'"; $sql.= ", ".(isset($this->fk_project)?$this->fk_project:"null"); + $sql.= ", ".(isset($this->cond_reglement_id)?$this->cond_reglement_id:"null"); + $sql.= ", ".(isset($this->mode_reglement_id)?$this->mode_reglement_id:"null"); $sql.= ", '".$this->db->escape($this->note_private)."'"; $sql.= ", '".$this->db->escape($this->note_public)."'"; $sql.= ", ".$user->id.","; @@ -300,17 +308,22 @@ class FactureFournisseur extends CommonInvoice $sql.= " t.fk_facture_source,"; $sql.= " t.fk_projet,"; $sql.= " t.fk_cond_reglement,"; + $sql.= " t.fk_mode_reglement,"; $sql.= " t.date_lim_reglement,"; $sql.= " t.note_private,"; $sql.= " t.note_public,"; $sql.= " t.model_pdf,"; $sql.= " t.import_key,"; $sql.= " t.extraparams,"; + $sql.= " cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle,"; + $sql.= " p.code as mode_reglement_code, p.libelle as mode_reglement_libelle,"; $sql.= ' s.nom as socnom, s.rowid as socid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t,'.MAIN_DB_PREFIX.'societe as s'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t'; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (t.fk_cond_reglement = cr.rowid)"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (t.fk_mode_reglement = p.id)"; if ($id) $sql.= " WHERE t.rowid=".$id; if ($ref) $sql.= " WHERE t.ref='".$this->db->escape($ref)."'"; - $sql.= ' AND t.fk_soc = s.rowid'; dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); @@ -352,7 +365,13 @@ class FactureFournisseur extends CommonInvoice $this->fk_user_valid = $obj->fk_user_valid; $this->fk_facture_source = $obj->fk_facture_source; $this->fk_project = $obj->fk_projet; - $this->fk_cond_reglement = $obj->fk_cond_reglement; + $this->cond_reglement_id = $obj->fk_cond_reglement; + $this->cond_reglement_code = $obj->cond_reglement_code; + $this->cond_reglement = $obj->cond_reglement_libelle; + $this->cond_reglement_doc = $obj->cond_reglement_libelle; + $this->mode_reglement_id = $obj->fk_mode_reglement; + $this->mode_reglement_code = $obj->mode_reglement_code; + $this->mode_reglement = $obj->mode_reglement_libelle; $this->date_echeance = $this->db->jdate($obj->date_lim_reglement); $this->note = $obj->note_private; // deprecated $this->note_private = $obj->note_private; diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 00d7589448a..1e932d64827 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -687,6 +687,8 @@ else if ($action == 'add' && $user->rights->fournisseur->commande->creer) // Creation commande $object->ref_supplier = GETPOST('refsupplier'); $object->socid = $socid; + $object->cond_reglement_id = GETPOST('cond_reglement_id'); + $object->mode_reglement_id = GETPOST('mode_reglement_id'); $object->note_private = GETPOST('note_private'); $object->note_public = GETPOST('note_public'); @@ -980,6 +982,9 @@ if ($action=="create") $societe=new Societe($db); $societe->fetch($socid); } + + $cond_reglement_id = $societe->cond_reglement_supplier_id; + $mode_reglement_id = $societe->mode_reglement_supplier_id; print '
'; print ''; @@ -1009,6 +1014,16 @@ if ($action=="create") print ''; print ''; + + // Payment term + print ''.$langs->trans('PaymentConditionsShort').''; + $form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id'); + print ''; + + // Payment mode + print ''.$langs->trans('PaymentMode').''; + $form->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id'); + print ''; print ''.$langs->trans('NotePublic').''; print ''; diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 5f717cce3d3..a45df719b7d 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -192,6 +192,18 @@ if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer) if ($result < 0) dol_print_error($db, $object->error); } +// conditions de reglement +if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) +{ + $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); +} + +// mode de reglement +else if ($action == 'setmode' && $user->rights->fournisseur->commande->creer) +{ + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); +} + // Set label elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) @@ -201,7 +213,6 @@ elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) $result=$object->update($user); if ($result < 0) dol_print_error($db); } - elseif ($action == 'setdatef' && $user->rights->fournisseur->facture->creer) { $object->fetch($id); @@ -293,6 +304,8 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer) $object->date_echeance = $datedue; $object->note_public = GETPOST('note_public'); $object->note_private = GETPOST('note_private'); + $object->cond_reglement_id = GETPOST('cond_reglement_id'); + $object->mode_reglement_id = GETPOST('mode_reglement_id'); $object->fk_project = ($tmpproject > 0) ? $tmpproject : null; // If creation from another object of another module @@ -1025,9 +1038,9 @@ if ($action == 'create') $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:''); - $soc = $objectsrc->client; - $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); - $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); + $soc = $objectsrc->thirdparty; + $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_supplier_id)?$soc->cond_reglement_supplier_id:1)); + $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_supplier_id)?$soc->mode_reglement_supplier_id:0)); $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; @@ -1040,6 +1053,8 @@ if ($action == 'create') } else { + $cond_reglement_id = $societe->cond_reglement_supplier_id; + $mode_reglement_id = $societe->mode_reglement_supplier_id; $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp); $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); @@ -1170,6 +1185,16 @@ if ($action == 'create') print ''.$langs->trans('DateMaxPayment').''; $form->select_date($datedue,'ech','','','',"add",1,1); print ''; + + // Payment term + print ''.$langs->trans('PaymentConditionsShort').''; + $form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id'); + print ''; + + // Payment mode + print ''.$langs->trans('PaymentMode').''; + $form->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id'); + print ''; // Project if (! empty($conf->projet->enabled)) @@ -1585,6 +1610,47 @@ else if ($action != 'editdate_lim_reglement' && $object->statut < 2 && $object->date_echeance && $object->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_warning($langs->trans('Late')); print ''; + // Conditions de reglement par defaut + $langs->load('bills'); + $form = new Form($db); + print ''; + print ''; + print '
'; + print $langs->trans('PaymentConditions'); + print ''; + if ($action != 'editconditions') print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; + print ''; + if ($action == 'editconditions') + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'cond_reglement_id'); + } + else + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'none'); + } + print ""; + print ''; + + // Mode of payment + $langs->load('bills'); + $form = new Form($db); + print ''; + print ''; + if ($action != 'editmode') print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; + print ''; + if ($action == 'editmode') + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); + } + else + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); + } + print ''; + // Status $alreadypaid=$object->getSommePaiement(); print ''.$langs->trans('Status').''.$object->getLibStatut(4,$alreadypaid).''; diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php index d61d49476bc..f813d720569 100644 --- a/htdocs/fourn/fiche.php +++ b/htdocs/fourn/fiche.php @@ -63,7 +63,20 @@ if ($action == 'setsupplieraccountancycode') } $action=""; } - +// conditions de reglement +if ($action == 'setconditions' && $user->rights->societe->creer) +{ + $object->fetch($id); + $result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int')); + if ($result < 0) dol_print_error($db,$object->error); +} +// mode de reglement +if ($action == 'setmode' && $user->rights->societe->creer) +{ + $object->fetch($id); + $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int')); + if ($result < 0) dol_print_error($db,$object->error); +} /* @@ -90,7 +103,7 @@ if ($object->fetch($id)) //print ''; print ''; - print ''; @@ -193,6 +206,46 @@ if ($object->fetch($id)) print ''; + + // Conditions de reglement par defaut + $langs->load('bills'); + $form = new Form($db); + print '"; + print ''; + + // Mode de reglement par defaut + print '"; + print ''; // Module Adherent if (! empty($conf->adherent->enabled)) 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 a25413f017b..eb649be5dec 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 @@ -282,3 +282,8 @@ INSERT INTO llx_c_departements ( code_departement, fk_region, cheflieu, tncc, nc ALTER TABLE llx_bordereau_cheque ADD ref_ext VARCHAR(255); ALTER TABLE llx_bordereau_cheque ADD tms timestamp; + +-- Task 1011 +ALTER TABLE `llx_societe` ADD `mode_reglement_supplier` TINYINT NOT NULL AFTER `cond_reglement` , +ADD `cond_reglement_supplier` TINYINT NOT NULL AFTER `mode_reglement_supplier`; +ALTER TABLE `llx_facture_fourn` ADD `fk_mode_reglement` TINYINT NOT NULL AFTER `fk_cond_reglement`; diff --git a/htdocs/install/mysql/tables/llx_facture_fourn.sql b/htdocs/install/mysql/tables/llx_facture_fourn.sql index c2d26a9c7cb..8722cc7ef8e 100644 --- a/htdocs/install/mysql/tables/llx_facture_fourn.sql +++ b/htdocs/install/mysql/tables/llx_facture_fourn.sql @@ -59,6 +59,7 @@ create table llx_facture_fourn fk_projet integer, -- projet auquel est associee la facture fk_cond_reglement integer DEFAULT 1 NOT NULL, -- condition de reglement (30 jours, fin de mois ...) + fk_mode_reglement integer DEFAULT 0 NOT NULL, -- mode de reglement (CHQ, VIR, ...) date_lim_reglement date, -- date limite de reglement note_private text, diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index 95ceadec503..9348ab3b6d5 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -77,6 +77,8 @@ create table llx_societe remise_client real DEFAULT 0, -- remise systematique pour le client mode_reglement tinyint, -- mode de reglement cond_reglement tinyint, -- condition de reglement + mode_reglement_supplier tinyint, -- mode de reglement fournisseur + cond_reglement_supplier tinyint, -- condition de reglement fournisseur tva_assuj tinyint DEFAULT 1, -- assujeti ou non a la TVA localtax1_assuj tinyint DEFAULT 0, -- assujeti ou non a local tax 1 localtax2_assuj tinyint DEFAULT 0, -- assujeti ou non a local tax 2 diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 6278b7bd8ab..60e4a1461ad 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -106,6 +106,8 @@ class Societe extends CommonObject var $remise_percent; var $mode_reglement_id; var $cond_reglement_id; + var $mode_reglement_supplier_id; + var $cond_reglement_supplier_id; var $client; // 0=no customer, 1=customer, 2=prospect, 3=customer and prospect var $prospect; // 0=no prospect, 1=prospect @@ -707,7 +709,7 @@ class Societe extends CommonObject $sql .= ', s.fk_forme_juridique as forme_juridique_code'; $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.localtax1_assuj, s.localtax2_assuj, s.fk_prospectlevel, s.default_lang, s.logo'; + $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 .= ', fj.libelle as forme_juridique'; $sql .= ', e.libelle as effectif'; @@ -826,6 +828,8 @@ class Societe extends CommonObject $this->remise_percent = $obj->remise_client; $this->mode_reglement_id = $obj->mode_reglement; $this->cond_reglement_id = $obj->cond_reglement; + $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier; + $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier; $this->client = $obj->client; $this->fournisseur = $obj->fournisseur;
'.$langs->trans("ThirdPartyName").''; + print '
'.$langs->trans("ThirdPartyName").''; $object->next_prev_filter="te.fournisseur = 1"; print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); print '
'.$langs->trans('VATIntra').''; print $object->tva_intra; print '
'; + print ''; + print '
'; + print $langs->trans('PaymentConditions'); + print ''; + if (($action != 'editconditions') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; + print '
'; + if ($action == 'editconditions') + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'cond_reglement_supplier_id',-1,1); + } + else + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'none'); + } + print "
'; + print ''; + print '
'; + print $langs->trans('PaymentMode'); + print ''; + if (($action != 'editmode') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; + print '
'; + if ($action == 'editmode') + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'mode_reglement_supplier_id'); + } + else + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'none'); + } + print "