New: Add ref_client field on template invoice

This commit is contained in:
Ferran Marcet 2019-04-26 13:53:22 +02:00
parent 0c432c28a8
commit 7a651b5071
5 changed files with 27 additions and 4 deletions

View File

@ -77,6 +77,7 @@ class FactureRec extends CommonInvoice
public $total;
public $db_table;
public $propalid;
public $ref_client;
public $date_last_gen;
public $date_when;
@ -166,6 +167,7 @@ class FactureRec extends CommonInvoice
$sql.= ", fk_account";
$sql.= ", fk_cond_reglement";
$sql.= ", fk_mode_reglement";
$sql.= ", ref_client";
$sql.= ", usenewprice";
$sql.= ", frequency";
$sql.= ", unit_frequency";
@ -194,6 +196,7 @@ class FactureRec extends CommonInvoice
$sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null");
$sql.= ", ".($facsrc->cond_reglement_id > 0 ? $this->db->escape($facsrc->cond_reglement_id) : "null");
$sql.= ", ".($facsrc->mode_reglement_id > 0 ? $this->db->escape($facsrc->mode_reglement_id) : "null");
$sql.= ",'".$this->db->escape($this->ref_client)."'";
$sql.= ", ".$this->usenewprice;
$sql.= ", ".$this->frequency;
$sql.= ", '".$this->db->escape($this->unit_frequency)."'";
@ -382,7 +385,7 @@ class FactureRec extends CommonInvoice
$sql.= ', f.note_private, f.note_public, f.fk_user_author';
$sql.= ', f.modelpdf';
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
$sql.= ', f.fk_account';
$sql.= ', f.fk_account, f.ref_client';
$sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate';
$sql.= ', f.generate_pdf';
$sql.= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
@ -1127,6 +1130,7 @@ class FactureRec extends CommonInvoice
$facture->brouillon = 1;
$facture->date = (empty($facturerec->date_when)?$now:$facturerec->date_when); // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
$facture->socid = $facturerec->socid;
$facture->ref_client = $facturerec->ref_client;
$invoiceidgenerated = $facture->create($user);
if ($invoiceidgenerated <= 0)

View File

@ -358,6 +358,7 @@ class Facture extends CommonInvoice
$this->socid = $_facrec->socid; // Invoice created on same thirdparty than template
$this->entity = $_facrec->entity; // Invoice created in same entity than template
$this->ref_client = $_facrec->ref_client;
// Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI
$this->fk_project = GETPOST('projectid', 'int') > 0 ? ((int) GETPOST('projectid', 'int')) : $_facrec->fk_project;

View File

@ -174,6 +174,7 @@ if (empty($reshook))
if (! $error)
{
$object->titre = GETPOST('titre', 'alpha');
$object->ref_client = GETPOST('ref_client', 'alpha');
$object->note_private = GETPOST('note_private', 'none');
$object->note_public = GETPOST('note_public', 'none');
$object->modelpdf = GETPOST('modelpdf', 'alpha');
@ -274,7 +275,7 @@ if (empty($reshook))
{
$object->setProject(GETPOST('projectid', 'int'));
}
// Set bank account
// Set titre
elseif ($action == 'setref' && $user->rights->facture->creer)
{
//var_dump(GETPOST('ref', 'alpha'));exit;
@ -286,6 +287,15 @@ if (empty($reshook))
}
else dol_print_error($db, $object->error, $object->errors);
}
elseif ($action == 'setref_client' && $user->rights->facture->creer)
{
$result=$object->setValueFrom('ref_client', GETPOST('ref_client', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY');
if ($result > 0)
{
$object->ref_client = GETPOST('ref_client', 'alpha');
}
else dol_print_error($db, $object->error, $object->errors);
}
// Set bank account
elseif ($action == 'setbankaccount' && $user->rights->facture->creer)
{
@ -997,6 +1007,11 @@ if ($action == 'create')
print '<input class="flat quatrevingtpercent" type="text" name="titre" value="'.$_POST["titre"].'">';
print '</td></tr>';
// Ref Client
print '<tr><td class="titlefieldcreate">'.$langs->trans("RefCustomer").'</td><td>';
print '<input class="flat quatrevingtpercent" type="text" name="ref_client" value="'.GETPOST('ref_client','alpha').'">';
print '</td></tr>';
// Third party
print '<tr><td class="titlefieldcreate">'.$langs->trans("Customer").'</td><td>'.$object->thirdparty->getNomUrl(1, 'customer').'</td>';
print '</tr>';
@ -1229,8 +1244,9 @@ else
$morehtmlref.='<div class="refidno">';
// Ref customer
//$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1);
//$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1);
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1);
$morehtmlref.='<br>';
// Thirdparty
$morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
// Project

View File

@ -297,3 +297,4 @@ ALTER TABLE llx_inventorydet DROP COLUMN pmp;
ALTER TABLE llx_inventorydet DROP COLUMN pa;
ALTER TABLE llx_inventorydet DROP COLUMN new_pmp;
ALTER TABLE llx_facture_rec ADD COLUMN ref_client varchar(255) after suspended;

View File

@ -29,6 +29,7 @@ create table llx_facture_rec
tms timestamp, -- date creation/modification
suspended integer DEFAULT 0, -- 1=suspended
ref_client varchar(255), -- reference for customer
amount double(24,8) DEFAULT 0 NOT NULL,
remise real DEFAULT 0,