Merge pull request #1143 from atm-maxime/mko1011

New # 1011 : payment term and mode for supplier, order and invoice
This commit is contained in:
Laurent Destailleur 2013-07-30 07:59:43 -07:00
commit 962545a70e
10 changed files with 181 additions and 12 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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 '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -1009,6 +1014,16 @@ if ($action=="create")
print '</tr>';
print '</td></tr>';
// Payment term
print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
$form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
print '</td></tr>';
// Payment mode
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
$form->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id');
print '</td></tr>';
print '<tr><td>'.$langs->trans('NotePublic').'</td>';
print '<td>';

View File

@ -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 '<tr><td>'.$langs->trans('DateMaxPayment').'</td><td>';
$form->select_date($datedue,'ech','','','',"add",1,1);
print '</td></tr>';
// Payment term
print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
$form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
print '</td></tr>';
// Payment mode
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
$form->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id');
print '</td></tr>';
// 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 '</td>';
// Conditions de reglement par defaut
$langs->load('bills');
$form = new Form($db);
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans('PaymentConditions');
print '<td>';
if ($action != 'editconditions') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 "</td>";
print '</tr>';
// Mode of payment
$langs->load('bills');
$form = new Form($db);
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans('PaymentMode');
print '</td>';
if ($action != 'editmode') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
// Status
$alreadypaid=$object->getSommePaiement();
print '<tr><td>'.$langs->trans('Status').'</td><td colspan="3">'.$object->getLibStatut(4,$alreadypaid).'</td></tr>';

View File

@ -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 '<tr><td valign="top" width="50%" class="notopnoleft">';
print '<table width="100%" class="border">';
print '<tr><td width="20%">'.$langs->trans("ThirdPartyName").'</td><td width="80%" colspan="3">';
print '<tr><td width="30%">'.$langs->trans("ThirdPartyName").'</td><td width="70%" colspan="3">';
$object->next_prev_filter="te.fournisseur = 1";
print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','','');
print '</td></tr>';
@ -193,6 +206,46 @@ if ($object->fetch($id))
print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td colspan="3">';
print $object->tva_intra;
print '</td></tr>';
// Conditions de reglement par defaut
$langs->load('bills');
$form = new Form($db);
print '<tr><td>';
print '<table width="100%" class="nobordernopadding"><tr><td>';
print $langs->trans('PaymentConditions');
print '<td>';
if (($action != 'editconditions') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
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 "</td>";
print '</tr>';
// Mode de reglement par defaut
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans('PaymentMode');
print '<td>';
if (($action != 'editmode') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
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 "</td>";
print '</tr>';
// Module Adherent
if (! empty($conf->adherent->enabled))

View File

@ -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`;

View File

@ -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,

View File

@ -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

View File

@ -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;