Merge pull request #20012 from atm-adrien/NEW_rec_invoices_15.0_newPR

NEW Recurring vendor invoices
This commit is contained in:
Laurent Destailleur 2022-02-10 10:09:47 +01:00 committed by GitHub
commit 77f1649adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 5625 additions and 25 deletions

View File

@ -95,6 +95,8 @@ if (GETPOST('roworder', 'alpha', 3) && GETPOST('table_element_line', 'aZ09', 3)
$perm = 1;
} elseif ($table_element_line == 'facture_fourn_det' && $user->rights->fournisseur->facture->creer) {
$perm = 1;
} elseif ($table_element_line == 'facture_fourn_det_rec' && $user->rights->fournisseur->facture->creer) {
$perm = 1;
} elseif ($table_element_line == 'ecm_files' && $fk_element == 'fk_product' && (!empty($user->rights->produit->creer) || !empty($user->rights->service->creer))) {
$perm = 1;
} elseif ($table_element_line == 'ecm_files' && $fk_element == 'fk_ticket' && !empty($user->rights->ticket->write)) {

View File

@ -3385,7 +3385,7 @@ abstract class CommonObject
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
} elseif ($this->element == 'facture' || $this->element == 'invoice') {
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
} elseif ($this->element == 'facture_fourn' || $this->element == 'supplier_invoice' || $this->element == 'invoice_supplier') {
} elseif ($this->element == 'facture_fourn' || $this->element == 'supplier_invoice' || $this->element == 'invoice_supplier' || $this->element == 'invoice_supplier_rec') {
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
} elseif ($this->element == 'order_supplier' || $this->element == 'supplier_order') {
$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
@ -3430,6 +3430,9 @@ abstract class CommonObject
$fieldtva = 'tva';
$fieldup = 'pu_ht';
}
if ($this->element == 'invoice_supplier_rec') {
$fieldup = 'pu_ht';
}
if ($this->element == 'expensereport') {
$fieldup = 'value_unit';
}
@ -3580,7 +3583,7 @@ abstract class CommonObject
if ($this->element == 'facture' || $this->element == 'facturerec') {
$fieldtva = 'total_tva';
}
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') {
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier' || $this->element == 'invoice_supplier_rec') {
$fieldtva = 'total_tva';
}
if ($this->element == 'propal') {
@ -8043,6 +8046,8 @@ abstract class CommonObject
$element = $this->element;
if ($element == 'facturerec') {
$element = 'facture';
} elseif ($element == 'invoice_supplier_rec') {
return $user->rights->fournisseur->facture;
}
return $user->rights->{$element};

View File

@ -200,7 +200,7 @@ function invoice_rec_prepare_head($object)
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/card-rec.php?id='.$object->id;
$head[$h][0] = DOL_URL_ROOT . '/compta/facture/card-rec.php?id=' . $object->id;
$head[$h][1] = $langs->trans("RepeatableInvoice");
$head[$h][2] = 'card';
$h++;
@ -216,6 +216,35 @@ function invoice_rec_prepare_head($object)
return $head;
}
/**
* Return array head with list of tabs to view object informations.
*
* @param Facture $object Invoice object
* @return array head array with tabs
*/
function supplier_invoice_rec_prepare_head($object)
{
global $db, $langs, $conf;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT . '/fourn/facture/card-rec.php?id=' . $object->id;
$head[$h][1] = $langs->trans("RepeatableSupplierInvoice");
$head[$h][2] = 'card';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec', 'remove');
return $head;
}
/**
* Return a HTML table that contains a pie chart of customer invoices
*

View File

@ -1087,6 +1087,8 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM
$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills_paid&search_status=2", $langs->trans("BillShortStatusPaid"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_paid');
}
$newmenu->add("/fourn/facture/list-rec.php?leftmenu=supplierinvoicestemplate_list", $langs->trans("ListOfTemplates"), 1, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'supplierinvoicestemplate_list');
$newmenu->add("/fourn/paiement/list.php?leftmenu=suppliers_bills_payment", $langs->trans("Payments"), 1, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_payment');
if ($usemenuhider || empty($leftmenu) || preg_match('/suppliers_bills/', $leftmenu)) {

View File

@ -129,6 +129,25 @@ class modFournisseur extends DolibarrModules
6=>array('file'=>'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton'=>'Home'),
);
$arraydate = dol_getdate(dol_now());
$datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
$this->cronjobs = array(
0 => array(
'label'=>'RecurringSupplierInvoices',
'jobtype'=>'method',
'class'=>'fourn/class/fournisseur.facture-rec.class.php',
'objectname'=>'FactureFournisseurRec',
'method'=>'createRecurringInvoices',
'parameters'=>'',
'comment'=>'Generate recurring supplier invoices',
'frequency'=>1,
'unitfrequency'=>3600 * 24,
'priority'=>50,
'status'=>1,
'datestart'=>$datestart
));
// Permissions
$this->rights = array();
$this->rights_class = 'fournisseur';

View File

@ -65,7 +65,7 @@ $colspan = 3; // Columns: total ht + col edit + col delete
if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
$colspan++; //Add column for Total (currency) if required
}
if (in_array($object->element, array('propal', 'commande', 'order', 'facture', 'facturerec', 'invoice', 'supplier_proposal', 'order_supplier', 'invoice_supplier'))) {
if (in_array($object->element, array('propal', 'commande', 'order', 'facture', 'facturerec', 'invoice', 'supplier_proposal', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
$colspan++; // With this, there is a column move button
}
@ -89,6 +89,8 @@ if (!empty($extrafields)) {
$objectline = new SupplierInvoiceLine($this->db);
} elseif ($this->table_element_line == 'facturedet_rec') {
$objectline = new FactureLigneRec($this->db);
} elseif ($this->table_element_line == 'facture_fourn_det_rec') {
$objectline = new FactureFournisseurLigneRec($this->db);
}
}
print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
@ -103,7 +105,7 @@ if ($nolinesbefore) {
<div id="add"></div><span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine'); ?></span>
</td>
<?php
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') { // We must have same test in printObjectLines
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
?>
<td class="linecolrefsupplier"><span id="title_fourn_ref"><?php echo $langs->trans('SupplierRef'); ?></span></td>
<?php
@ -343,7 +345,7 @@ if ($nolinesbefore) {
$doleditor = new DolEditor('dp_desc', GETPOST('dp_desc', 'restricthtml'), '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT) ? 100 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enabled, $nbrows, '98%');
$doleditor->Create();
// Show autofill date for recurring invoices
if (!empty($conf->service->enabled) && $object->element == 'facturerec') {
if (!empty($conf->service->enabled) && ($object->element == 'facturerec' || $object->element == 'invoice_supplier_rec')) {
echo '<div class="divlinefordates"><br>';
echo $langs->trans('AutoFillDateFrom').' ';
echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
@ -362,7 +364,7 @@ if ($nolinesbefore) {
}
}
echo '</td>';
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') { // We must have same test in printObjectLines
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
$coldisplay++;
?>
<td class="nobottom linecolresupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth125" value="<?php echo (GETPOSTISSET("fourn_ref") ? GETPOST("fourn_ref", 'alpha', 2) : ''); ?>"></td>

View File

@ -66,7 +66,7 @@ $colspan = 3; // Col total ht + col edit + col delete
if (!empty($inputalsopricewithtax)) {
$colspan++; // We add 1 if col total ttc
}
if (in_array($object->element, array('propal', 'supplier_proposal', 'facture', 'facturerec', 'invoice', 'commande', 'order', 'order_supplier', 'invoice_supplier'))) {
if (in_array($object->element, array('propal', 'supplier_proposal', 'facture', 'facturerec', 'invoice', 'commande', 'order', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
$colspan++; // With this, there is a column move button
}
if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
@ -170,7 +170,11 @@ $coldisplay++;
}
// Show autofill date for recuring invoices
if (!empty($conf->service->enabled) && $line->product_type == 1 && $line->element == 'facturedetrec') {
if (!empty($conf->service->enabled) && $line->product_type == 1 && ($line->element == 'facturedetrec' || $line->element == 'invoice_supplier_det_rec')) {
if ($line->element == 'invoice_supplier_det_rec') {
$line->date_start_fill = $line->date_start;
$line->date_end_fill = $line->date_end;
}
echo '<br>';
echo $langs->trans('AutoFillDateFrom').' ';
echo $form->selectyesno('date_start_fill', GETPOSTISSET('date_start_fill') ? GETPOST('date_start_fill', 'int') : $line->date_start_fill, 1);
@ -183,7 +187,7 @@ $coldisplay++;
</td>
<?php
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') { // We must have same test in printObjectLines
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
$coldisplay++;
?>
<td class="right"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth150" value="<?php echo GETPOSTISSET('fourn_ref') ? GETPOST('fourn_ref') : ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn); ?>"></td>

View File

@ -55,7 +55,7 @@ if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
// Supplier ref
if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') {
if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier' || $this->element == 'invoice_supplier_rec') {
print '<td class="linerefsupplier maxwidth125"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>';
}

View File

@ -162,7 +162,11 @@ if (($line->info_bits & 2) == 2) {
}
// Show date range
if ($line->element == 'facturedetrec') {
if ($line->element == 'facturedetrec' || $line->element == 'invoice_supplier_det_rec') {
if ($line->element == 'invoice_supplier_det_rec' && $line->product_type != Product::TYPE_PRODUCT) {
$line->date_start_fill = $line->date_start;
$line->date_end_fill = $line->date_end;
}
if ($line->date_start_fill || $line->date_end_fill) {
print '<div class="clearboth nowraponall daterangeofline-facturedetrec">';
}
@ -202,6 +206,8 @@ if (($line->info_bits & 2) == 2) {
if ($line->fk_product > 0 && !empty($conf->global->PRODUIT_DESC_IN_FORM)) {
if ($line->element == 'facturedetrec') {
print (!empty($line->description) && $line->description != $line->product_label) ? (($line->date_start_fill || $line->date_end_fill) ? '' : '<br>').'<br>'.dol_htmlentitiesbr($line->description) : '';
} elseif ($line->element == 'invoice_supplier_det_rec') {
print (!empty($line->description) && $line->description != $line->label) ? (($line->date_start || $line->date_end) ? '' : '<br>').'<br>'.dol_htmlentitiesbr($line->description) : '';
} else {
print (!empty($line->description) && $line->description != $line->product_label) ? (($line->date_start || $line->date_end) ? '' : '<br>').'<br>'.dol_htmlentitiesbr($line->description) : '';
}
@ -239,7 +245,7 @@ if (!empty($conf->accounting->enabled) && $line->fk_accounting_account > 0) {
}
print '</td>';
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') { // We must have same test in printObjectLines
if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
print '<td class="linecolrefsupplier">';
print ($line->ref_fourn ? $line->ref_fourn : $line->ref_supplier);
print '</td>';

File diff suppressed because it is too large Load Diff

View File

@ -251,6 +251,8 @@ class FactureFournisseur extends CommonInvoice
*/
public $fk_facture_source;
public $fac_rec;
public $fields = array(
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
@ -410,6 +412,128 @@ class FactureFournisseur extends CommonInvoice
$this->db->begin();
// Create invoice from a template recurring invoice
if ($this->fac_rec > 0) {
$this->fk_fac_rec_source = $this->fac_rec;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture-rec.class.php';
$_facrec = new FactureFournisseurRec($this->db);
$result = $_facrec->fetch($this->fac_rec);
$result = $_facrec->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0); // This load $_facrec->linkedObjectsIds
// Define some dates
if (! empty($_facrec->frequency)) {
$originaldatewhen = $_facrec->date_when;
$nextdatewhen = dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
$previousdaynextdatewhen = dol_time_plus_duree($nextdatewhen, -1, 'd');
$this->socid = $_facrec->socid;
}
$this->entity = $_facrec->entity; // Invoice created in same entity than template
// 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_projet = GETPOST('projectid', 'int') > 0 ? ((int) GETPOST('projectid', 'int')) : $_facrec->fk_projet;
$this->note_public = GETPOST('note_public', 'restricthtml') ? GETPOST('note_public', 'restricthtml') : $_facrec->note_public;
$this->note_private = GETPOST('note_private', 'restricthtml') ? GETPOST('note_private', 'restricthtml') : $_facrec->note_private;
$this->model_pdf = GETPOST('model', 'alpha') ? GETPOST('model', 'alpha') : $_facrec->model_pdf;
$this->cond_reglement_id = GETPOST('cond_reglement_id', 'int') > 0 ? ((int) GETPOST('cond_reglement_id', 'int')) : $_facrec->cond_reglement_id;
$this->mode_reglement_id = GETPOST('mode_reglement_id', 'int') > 0 ? ((int) GETPOST('mode_reglement_id', 'int')) : $_facrec->mode_reglement_id;
$this->fk_account = GETPOST('fk_account') > 0 ? ((int) GETPOST('fk_account')) : $_facrec->fk_account;
// Set here to have this defined for substitution into notes, should be recalculated after adding lines to get same result
$this->total_ht = $_facrec->total_ht;
$this->total_ttc = $_facrec->total_ttc;
// Fields always coming from template
$this->remise = $_facrec->remise;
$this->fk_incoterms = $_facrec->fk_incoterms;
$this->location_incoterms = $_facrec->location_incoterms;
// Clean parameters
if (! $this->type) {
$this->type = self::TYPE_STANDARD;
}
if (! empty(GETPOST('ref_supplier'))) {
$this->ref_supplier = trim($this->ref_supplier);
} else {
$this->ref_supplier = trim($this->ref_supplier . '_' . ($_facrec->nb_gen_done + 1));
}
$this->note_public = trim($this->note_public);
$this->note_private = trim($this->note_private);
$this->note_private = dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->titre));
$this->array_options = $_facrec->array_options;
//if (! $this->remise) $this->remise = 0;
if (! $this->mode_reglement_id) {
$this->mode_reglement_id = 0;
}
$this->brouillon = 1;
$this->status = self::STATUS_DRAFT;
$this->statut = self::STATUS_DRAFT;
$this->linked_objects = $_facrec->linkedObjectsIds;
// We do not add link to template invoice or next invoice will be linked to all generated invoices
//$this->linked_objects['facturerec'][0] = $this->fac_rec;
$forceduedate = $this->calculate_date_lim_reglement();
// For recurring invoices, update date and number of last generation of recurring template invoice, before inserting new invoice
if ($_facrec->frequency > 0) {
dol_syslog("This is a recurring invoice so we set date_last_gen and next date_when");
if (empty($_facrec->date_when)) {
$_facrec->date_when = $now;
}
$next_date = $_facrec->getNextDate(); // Calculate next date
$result = $_facrec->setValueFrom('date_last_gen', $now, '', null, 'date', '', $user, '');
//$_facrec->setValueFrom('nb_gen_done', $_facrec->nb_gen_done + 1); // Not required, +1 already included into setNextDate when second param is 1.
$result = $_facrec->setNextDate($next_date, 1);
}
// Define lang of customer
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->thirdparty->default_lang)) {
$newlang = $this->thirdparty->default_lang; // for proposal, order, invoice, ...
}
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->default_lang)) {
$newlang = $this->default_lang; // for thirdparty
}
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $this);
$substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = dol_print_date(dol_time_plus_duree($this->date, -1, 'm'), '%m');
$substitutionarray['__INVOICE_MONTH__'] = dol_print_date($this->date, '%m');
$substitutionarray['__INVOICE_NEXT_MONTH__'] = dol_print_date(dol_time_plus_duree($this->date, 1, 'm'), '%m');
$substitutionarray['__INVOICE_PREVIOUS_MONTH_TEXT__'] = dol_print_date(dol_time_plus_duree($this->date, -1, 'm'), '%B');
$substitutionarray['__INVOICE_MONTH_TEXT__'] = dol_print_date($this->date, '%B');
$substitutionarray['__INVOICE_NEXT_MONTH_TEXT__'] = dol_print_date(dol_time_plus_duree($this->date, 1, 'm'), '%B');
$substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = dol_print_date(dol_time_plus_duree($this->date, -1, 'y'), '%Y');
$substitutionarray['__INVOICE_YEAR__'] = dol_print_date($this->date, '%Y');
$substitutionarray['__INVOICE_NEXT_YEAR__'] = dol_print_date(dol_time_plus_duree($this->date, 1, 'y'), '%Y');
// Only for template invoice
$substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = dol_print_date($originaldatewhen, 'dayhour');
$substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($nextdatewhen, 'dayhour');
$substitutionarray['__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($previousdaynextdatewhen, 'dayhour');
$substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $_facrec->nb_gen_done;
$substitutionarray['__INVOICE_COUNTER_MAX__'] = $_facrec->nb_gen_max;
complete_substitutions_array($substitutionarray, $outputlangs);
$this->note_public = make_substitutions($this->note_public, $substitutionarray);
$this->note_private = make_substitutions($this->note_private, $substitutionarray);
}
// Define due date if not already defined
if (! empty($forceduedate)) {
$this->date_echeance = $forceduedate;
}
if (!$remise) {
$remise = 0;
}
@ -437,6 +561,7 @@ class FactureFournisseur extends CommonInvoice
$sql .= ", multicurrency_code";
$sql .= ", multicurrency_tx";
$sql .= ", fk_facture_source";
$sql .= ", fk_fac_rec_source";
$sql .= ")";
$sql .= " VALUES (";
$sql .= "'(PROV)'";
@ -462,6 +587,7 @@ class FactureFournisseur extends CommonInvoice
$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
$sql .= ", ".(double) $this->multicurrency_tx;
$sql .= ", ".(isset($this->fk_facture_source) ? $this->fk_facture_source : "NULL");
$sql .= ", ".(isset($this->fk_fac_rec_source) ? $this->fk_fac_rec_source : "NULL");
$sql .= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG);
@ -506,7 +632,7 @@ class FactureFournisseur extends CommonInvoice
}
}
if (count($this->lines) && is_object($this->lines[0])) { // If this->lines is array of InvoiceLines (preferred mode)
if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) { // If this->lines is array of InvoiceLines (preferred mode)
dol_syslog("There is ".count($this->lines)." lines that are invoice lines objects");
foreach ($this->lines as $i => $val) {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn, special_code, fk_remise_except)';
@ -516,7 +642,7 @@ class FactureFournisseur extends CommonInvoice
if ($resql_insert) {
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
$this->updateline(
$res = $this->updateline(
$idligne,
$this->lines[$i]->description,
$this->lines[$i]->pu_ht,
@ -543,8 +669,7 @@ class FactureFournisseur extends CommonInvoice
return -5;
}
}
} else // If this->lines is an array of invoice line arrays
{
} elseif (!$error && empty($this->fac_rec)) { // If this->lines is an array of invoice line arrays
dol_syslog("There is ".count($this->lines)." lines that are array lines");
foreach ($this->lines as $i => $val) {
$line = $this->lines[$i];
@ -591,6 +716,92 @@ class FactureFournisseur extends CommonInvoice
}
}
/*
* Insert lines of template invoices
*/
if (! $error && $this->fac_rec > 0) {
foreach ($_facrec->lines as $i => $val) {
if ($_facrec->lines[$i]->fk_product) {
$prod = new Product($this->db);
$res = $prod->fetch($_facrec->lines[$i]->fk_product);
}
// For line from template invoice, we use data from template invoice
/*
$tva_tx = get_default_tva($mysoc,$soc,$prod->id);
$tva_npr = get_default_npr($mysoc,$soc,$prod->id);
if (empty($tva_tx)) $tva_npr=0;
$localtax1_tx=get_localtax($tva_tx,1,$soc,$mysoc,$tva_npr);
$localtax2_tx=get_localtax($tva_tx,2,$soc,$mysoc,$tva_npr);
*/
$tva_tx = $_facrec->lines[$i]->tva_tx . ($_facrec->lines[$i]->vat_src_code ? '(' . $_facrec->lines[$i]->vat_src_code . ')' : '');
$tva_npr = $_facrec->lines[$i]->info_bits;
if (empty($tva_tx)) {
$tva_npr = 0;
}
$localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
$localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
$fk_product_fournisseur_price = empty($_facrec->lines[$i]->fk_product_fournisseur_price) ? null : $_facrec->lines[$i]->fk_product_fournisseur_price;
$buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
// If buyprice not defined from template invoice, we try to guess the best value
if (! $buyprice && $_facrec->lines[$i]->fk_product > 0) {
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
$producttmp = new ProductFournisseur($this->db);
$producttmp->fetch($_facrec->lines[$i]->fk_product);
// If margin module defined on costprice, we try the costprice
// If not defined or if module margin defined and pmp and stock module enabled, we try pmp price
// else we get the best supplier price
if ($conf->global->MARGIN_TYPE == 'costprice' && ! empty($producttmp->cost_price)) {
$buyprice = $producttmp->cost_price;
} elseif (! empty($conf->stock->enabled) && ($conf->global->MARGIN_TYPE == 'costprice' || $conf->global->MARGIN_TYPE == 'pmp') && ! empty($producttmp->pmp)) {
$buyprice = $producttmp->pmp;
} else {
if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0) {
if ($producttmp->product_fourn_price_id > 0) {
$buyprice = price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise, 'MU');
}
}
}
}
$result_insert = $this->addline(
$_facrec->lines[$i]->description,
$_facrec->lines[$i]->pu_ht,
$tva_tx,
$localtax1_tx,
$localtax2_tx,
$_facrec->lines[$i]->qty,
$_facrec->lines[$i]->fk_product,
$_facrec->lines[$i]->remise_percent,
($_facrec->lines[$i]->date_start == 1 && $this->date) ? $this->date : '',
($_facrec->lines[$i]->date_end == 1 && $previousdaynextdatewhen) ? $previousdaynextdatewhen : '',
0,
$_facrec->lines[$i]->info_bits,
'HT',
0,
$_facrec->lines[$i]->rang,
false,
$_facrec->lines[$i]->array_options,
$_facrec->lines[$i]->fk_unit,
0,
0,
$_facrec->lines[$i]->ref_supplier,
$_facrec->lines[$i]->special_code,
0,
0,
);
if ($result_insert < 0) {
$error++;
$this->error = $this->db->error();
break;
}
}
}
// Update total price
$result = $this->update_price();
if ($result > 0) {
@ -674,6 +885,7 @@ class FactureFournisseur extends CommonInvoice
$sql .= " t.fk_user_author,";
$sql .= " t.fk_user_valid,";
$sql .= " t.fk_facture_source,";
$sql .= " t.fk_fac_rec_source,";
$sql .= " t.fk_projet as fk_project,";
$sql .= " t.fk_cond_reglement,";
$sql .= " t.fk_account,";
@ -741,6 +953,7 @@ class FactureFournisseur extends CommonInvoice
$this->author = $obj->fk_user_author;
$this->fk_user_valid = $obj->fk_user_valid;
$this->fk_facture_source = $obj->fk_facture_source;
$this->fk_fac_rec_source = $obj->fk_fac_rec_source;
$this->fk_project = $obj->fk_project;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->cond_reglement_code = $obj->cond_reglement_code;
@ -3412,7 +3625,7 @@ class SupplierInvoiceLine extends CommonObjectLine
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET";
$sql .= " description ='".$this->db->escape($this->description)."'";
$sql .= ' description ="'.$this->db->escape($this->description).'"';
$sql .= ", ref ='".$this->db->escape($this->ref_supplier ? $this->ref_supplier : $this->ref)."'";
$sql .= ", date_start = ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : "null");
$sql .= ", date_end = ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : "null");

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
@ -883,8 +884,52 @@ if (empty($reshook)) {
}
}
// Standard invoice or Deposit invoice, created from a Predefined template invoice
if ((GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT) && GETPOST('fac_rec', 'int') > 0) {
if (empty($dateinvoice)) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
$action = 'create';
} elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
$error++;
setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
$action = 'create';
}
if (!$error) {
$object->socid = GETPOST('socid', 'int');
$object->type = GETPOST('type');
$object->ref = GETPOST('ref');
$object->date = $dateinvoice;
$object->note_public = trim(GETPOST('note_public', 'restricthtml'));
$object->note_private = trim(GETPOST('note_private', 'restricthtml'));
$object->ref_client = GETPOST('ref_client');
$object->model_pdf = GETPOST('model');
$object->fk_project = GETPOST('projectid', 'int');
$object->cond_reglement_id = (GETPOST('type') == 3 ? 1 : GETPOST('cond_reglement_id'));
$object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
$object->fk_account = GETPOST('fk_account', 'int');
$object->amount = price2num(GETPOST('amount'));
$object->remise_absolue = price2num(GETPOST('remise_absolue'), 'MU');
$object->remise_percent = price2num(GETPOST('remise_percent'), '', 2);
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
// Source facture
$object->fac_rec = GETPOST('fac_rec', 'int');
$fac_rec = new FactureFournisseurRec($db);
$fac_rec->fetch($object->fac_rec);
$fac_rec->fetch_lines();
$object->lines = $fac_rec->lines;
$id = $object->create($user); // This include recopy of links from recurring invoice and recurring invoice lines
}
}
// Standard invoice or Deposit invoice, not from a Predefined template invoice
if (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT) {
if (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT && GETPOST('fac_rec') <= 0) {
if (GETPOST('socid', 'int') < 1) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors');
$action = 'create';
@ -1957,11 +2002,17 @@ if ($action == 'create') {
// Ref
print '<tr><td class="titlefieldcreate">'.$langs->trans('Ref').'</td><td>'.$langs->trans('Draft').'</td></tr>';
$exampletemplateinvoice = new FactureFournisseurRec($db);
$invoice_predefined = new FactureFournisseurRec($db);
if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) {
$invoice_predefined->fetch(GETPOST('fac_rec', 'int'));
}
// Third party
print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
print '<td>';
if ($societe->id > 0) {
if ($societe->id > 0 && (!GETPOST('fac_rec', 'int') || !empty($invoice_predefined->frequency))) {
$absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1);
print $societe->getNomUrl(1, 'supplier');
print '<input type="hidden" name="socid" value="'.$societe->id.'">';
@ -1973,16 +2024,86 @@ if ($action == 'create') {
$(document).ready(function() {
$("#socid").change(function() {
var socid = $(this).val();
// reload page
window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid;
var fac_rec = $(\'#fac_rec\').val();
window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&fac_rec="+fac_rec;
});
});
</script>';
}
print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
if (!GETPOST('fac_rec', 'int')) {
print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
}
}
print '</td></tr>';
// Overwrite some values if creation of invoice is from a predefined invoice
if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) {
$invoice_predefined->fetch(GETPOST('fac_rec', 'int'));
$dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later
if (empty($projectid)) {
$projectid = $invoice_predefined->fk_project;
}
$cond_reglement_id = $invoice_predefined->cond_reglement_id;
$mode_reglement_id = $invoice_predefined->mode_reglement_id;
$fk_account = $invoice_predefined->fk_account;
$note_public = $invoice_predefined->note_public;
$note_private = $invoice_predefined->note_private;
if (!empty($invoice_predefined->multicurrency_code)) {
$currency_code = $invoice_predefined->multicurrency_code;
}
if (!empty($invoice_predefined->multicurrency_tx)) {
$currency_tx = $invoice_predefined->multicurrency_tx;
}
$sql = 'SELECT r.rowid, r.titre as title, r.total_ttc';
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_rec as r';
$sql .= ' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
if ($num > 0) {
print '<tr><td>'.$langs->trans('CreateFromRepeatableInvoice').'</td><td>';
//print '<input type="hidden" name="fac_rec" id="fac_rec" value="'.GETPOST('fac_rec', 'int').'">';
print '<select class="flat" id="fac_rec" name="fac_rec">'; // We may want to change the template to use
print '<option value="0" selected></option>';
while ($i < $num) {
$objp = $db->fetch_object($resql);
print '<option value="'.$objp->rowid.'"';
if (GETPOST('fac_rec', 'int') == $objp->rowid) {
print ' selected';
$exampletemplateinvoice->fetch(GETPOST('fac_rec', 'int'));
}
print '>'.$objp->title.' ('.price($objp->total_ttc).' '.$langs->trans("TTC").')</option>';
$i++;
}
print '</select>';
// Option to reload page to retrieve customer informations. Note, this clear other input
if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
print '<script type="text/javascript">
$(document).ready(function() {
$("#fac_rec").change(function() {
console.log("We have changed the template invoice - Reload page");
var fac_rec = $(this).val();
var socid = $(\'#socid\').val();
// For template invoice change, we must reuse data of template, not input already done, so we call a GET with action=create, not a POST submit.
window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&fac_rec="+fac_rec;
});
});
</script>';
}
print '</td></tr>';
}
$db->free($resql);
} else {
dol_print_error($db);
}
}
// Ref supplier
print '<tr><td class="fieldrequired">'.$langs->trans('RefSupplier').'</td><td><input name="ref_supplier" value="'.(isset($_POST['ref_supplier']) ? $_POST['ref_supplier'] : $objectsrc->ref_supplier).'" type="text"';
if ($societe->id > 0) {
@ -2288,6 +2409,34 @@ if ($action == 'create') {
print '</td></tr>';
}
// Help of substitution key
$htmltext = '';
if (GETPOST('fac_rec', 'int') > 0) {
$dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
if (empty($dateexample)) {
$dateexample = dol_now();
}
$substitutionarray = array(
'__TOTAL_HT__' => $langs->trans("AmountHT").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ht).')',
'__TOTAL_TTC__' => $langs->trans("AmountTTC").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ttc).')',
'__INVOICE_PREVIOUS_MONTH__' => $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%m').')',
'__INVOICE_MONTH__' => $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%m').')',
'__INVOICE_NEXT_MONTH__' => $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%m').')',
'__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%B').')',
'__INVOICE_MONTH_TEXT__' => $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%B').')',
'__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')',
'__INVOICE_PREVIOUS_YEAR__' => $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'), '%Y').')',
'__INVOICE_YEAR__' => $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%Y').')',
'__INVOICE_NEXT_YEAR__' => $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'), '%Y').')'
);
$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
foreach ($substitutionarray as $key => $val) {
$htmltext .= $key.' = '.$langs->trans($val).'<br>';
}
$htmltext .= '</i>';
}
// Intracomm report
if (!empty($conf->intracommreport->enabled)) {
$langs->loadLangs(array("intracommreport"));
@ -2776,6 +2925,19 @@ if ($action == 'create') {
print '</span><br>';
}
}
if ($object->fk_fac_rec_source > 0) {
$tmptemplate = new FactureFournisseurRec($db);
$result = $tmptemplate->fetch($object->fk_fac_rec_source);
if ($result > 0) {
print ' <span class="opacitymediumbycolor paddingleft">';
$link = '<a href="'.DOL_URL_ROOT.'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.'">'.dol_escape_htmltag($tmptemplate->titre).'</a>';
$s = $langs->transnoentities("GeneratedFromSupplierTemplate", $link);
print $s;
print '</span>';
}
}
print '</td></tr>';
@ -3559,6 +3721,13 @@ if ($action == 'create') {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=clone&amp;socid='.$object->socid.'">'.$langs->trans('ToClone').'</a>';
}
// Clone as predefined / Create template
if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_DEPOSIT) && $object->statut == 0 && $usercancreate) {
if (!$objectidnext && count($object->lines) > 0) {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card-rec.php?facid='.$object->id.'&amp;action=create">'.$langs->trans("ChangeIntoRepeatableInvoice").'</a>';
}
}
// Delete
$isErasable = $object->is_erasable();
if ($action != 'confirm_edit' && ($user->rights->fournisseur->facture->supprimer || ($usercancreate && $isErasable == 1))) { // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions)

View File

@ -0,0 +1,922 @@
<?php
/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2015-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/compta/facture/invoicetemplate_list.php
* \ingroup facture
* \brief Page to show list of template/recurring invoices
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Load translation files required by the page
$langs->loadLangs(array('bills', 'compta', 'admin', 'other', 'suppliers'));
$action = GETPOST('action', 'alpha');
$massaction = GETPOST('massaction', 'alpha');
$show_files = GETPOST('show_files', 'int');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$toselect = GETPOST('toselect', 'array');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicetemplatelist'; // To manage different context of search
$optioncss = GETPOST('optioncss', 'alpha');
$socid = GETPOST('socid', 'int');
// Security check
$id = (GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int'));
$lineid = GETPOST('lineid', 'int');
$ref = GETPOST('ref', 'alpha');
if ($user->socid) {
$socid = $user->socid;
}
$objecttype = 'facture_fourn_rec';
if ($action == "create" || $action == "add") {
$objecttype = '';
}
$result = restrictedArea($user, 'facture', $id, $objecttype);
$search_ref = GETPOST('search_ref');
$search_societe = GETPOST('search_societe');
$search_montant_ht = GETPOST('search_montant_ht');
$search_montant_vat = GETPOST('search_montant_vat');
$search_montant_ttc = GETPOST('search_montant_ttc');
$search_payment_mode = GETPOST('search_payment_mode');
$search_payment_term = GETPOST('search_payment_term');
$search_date_startday = GETPOST('search_date_startday', 'int');
$search_date_startmonth = GETPOST('search_date_startmonth', 'int');
$search_date_startyear = GETPOST('search_date_startyear', 'int');
$search_date_endday = GETPOST('search_date_endday', 'int');
$search_date_endmonth = GETPOST('search_date_endmonth', 'int');
$search_date_endyear = GETPOST('search_date_endyear', 'int');
$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
$search_date_when_startday = GETPOST('search_date_when_startday', 'int');
$search_date_when_startmonth = GETPOST('search_date_when_startmonth', 'int');
$search_date_when_startyear = GETPOST('search_date_when_startyear', 'int');
$search_date_when_endday = GETPOST('search_date_when_endday', 'int');
$search_date_when_endmonth = GETPOST('search_date_when_endmonth', 'int');
$search_date_when_endyear = GETPOST('search_date_when_endyear', 'int');
$search_date_when_start = dol_mktime(0, 0, 0, $search_date_when_startmonth, $search_date_when_startday, $search_date_when_startyear); // Use tzserver
$search_date_when_end = dol_mktime(23, 59, 59, $search_date_when_endmonth, $search_date_when_endday, $search_date_when_endyear);
$search_recurring = GETPOST('search_recurring', 'int');
$search_frequency = GETPOST('search_frequency', 'alpha');
$search_unit_frequency = GETPOST('search_unit_frequency', 'alpha');
$search_status = GETPOST('search_status', 'int');
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST('page', 'int');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
if (!$sortorder) {
$sortorder = 'DESC';
}
if (!$sortfield) {
$sortfield = 'f.titre';
}
$pageprev = $page - 1;
$pagenext = $page + 1;
$object = new FactureFournisseurRec($db);
if (($id > 0 || $ref) && $action != 'create' && $action != 'add') {
$ret = $object->fetch($id, $ref);
if (!$ret) {
setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
}
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('supplierinvoicereclist'));
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
$permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
$permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php
$arrayfields = array(
'f.titre'=>array('label'=>'Ref', 'checked'=>1),
's.nom'=>array('label'=>'ThirdParty', 'checked'=>1),
'f.total_ht'=>array('label'=>'AmountHT', 'checked'=>1),
'f.total_tva'=>array('label'=>'AmountVAT', 'checked'=>1),
'f.total_ttc'=>array('label'=>'AmountTTC', 'checked'=>1),
'f.fk_mode_reglement'=>array('label'=>'PaymentMode', 'checked'=>0),
'f.fk_cond_reglement'=>array('label'=>'PaymentTerm', 'checked'=>0),
'recurring'=>array('label'=>'RecurringInvoice', 'checked'=>1),
'f.frequency'=>array('label'=>'Frequency', 'checked'=>1),
'f.unit_frequency'=>array('label'=>'FrequencyUnit', 'checked'=>1),
'f.nb_gen_done'=>array('label'=>'NbOfGenerationDoneShort', 'checked'=>1),
'f.date_last_gen'=>array('label'=>'DateLastGenerationShort', 'checked'=>1),
'f.date_when'=>array('label'=>'NextDateToExecutionShort', 'checked'=>1),
'f.fk_user_author'=>array('label'=>'UserCreation', 'checked'=>0, 'position'=>500),
'f.fk_user_modif'=>array('label'=>'UserModification', 'checked'=>0, 'position'=>505),
'f.datec'=>array('label'=>'DateCreation', 'checked'=>0, 'position'=>520),
'f.tms'=>array('label'=>'DateModificationShort', 'checked'=>0, 'position'=>525),
'suspended '=>array('label'=>'Status', 'checked'=>1, 'position'=>1000),
);
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
$object->fields = dol_sort_array($object->fields, 'position');
$arrayfields = dol_sort_array($arrayfields, 'position');
if ($socid > 0) {
$tmpthirdparty = new Societe($db);
$res = $tmpthirdparty->fetch($socid);
if ($res > 0) {
$search_societe = $tmpthirdparty->name;
}
}
$objecttype = 'facture_fourn_rec';
$result = restrictedArea($user, 'facture', $object->id, $objecttype);
/*
* Actions
*/
if (GETPOST('cancel', 'alpha')) {
$action = 'list';
$massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
if (GETPOST('cancel', 'alpha')) {
$action = '';
}
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Do we click on purge search criteria ?
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
$search_ref = '';
$search_societe = '';
$search_montant_ht = '';
$search_montant_vat = '';
$search_montant_ttc = '';
$search_payment_mode = '';
$search_payment_term = '';
$search_date_startday = '';
$search_date_startmonth = '';
$search_date_startyear = '';
$search_date_endday = '';
$search_date_endmonth = '';
$search_date_endyear = '';
$search_date_start = '';
$search_date_end = '';
$search_date_when_startday = '';
$search_date_when_startmonth = '';
$search_date_when_startyear = '';
$search_date_when_endday = '';
$search_date_when_endmonth = '';
$search_date_when_endyear = '';
$search_date_when_start = '';
$search_date_when_end = '';
$search_recurring = '';
$search_frequency = '';
$search_unit_frequency = '';
$search_status = '';
$search_array_options = array();
}
// Mass actions
/*$objectclass='MyObject';
$objectlabel='MyObject';
$permissiontoread = $user->rights->mymodule->read;
$permissiontodelete = $user->rights->mymodule->delete;
$uploaddir = $conf->mymodule->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
}
/*
* View
*/
$help_url = '';
llxHeader('', $langs->trans("RepeatableSupplierInvoices"), $help_url);
$form = new Form($db);
$formother = new FormOther($db);
if (!empty($conf->projet->enabled)) {
$formproject = new FormProjets($db);
}
$companystatic = new Societe($db);
$supplierinvoicerectmp = new FactureFournisseurRec($db);
$tmpuser = new User($db);
$now = dol_now();
$tmparray = dol_getdate($now);
$today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
/*
* List mode
*/
$sql = "SELECT s.nom as name, s.rowid as socid, f.rowid as facid, f.titre as title, f.total_ht, f.total_tva, f.total_ttc, f.frequency, f.unit_frequency,";
$sql .= " f.nb_gen_done, f.nb_gen_max, f.date_last_gen, f.date_when, f.suspended,";
$sql .= " f.datec, f.fk_user_author, f.tms, f.fk_user_modif,";
$sql .= " f.fk_cond_reglement, f.fk_mode_reglement";
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
}
}
// Add fields from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
$sql = preg_replace('/,\s*$/', '', $sql);
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn_rec as f';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_rec_extrafields as ef ON ef.fk_object = f.rowid';
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
}
$sql .= ' WHERE f.fk_soc = s.rowid';
$sql .= ' AND f.entity IN ('.getEntity('invoice').')';
if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '. (int) $user->id;
}
if ($search_ref) {
$sql .= natural_search('f.titre', $search_ref);
}
if ($socid) {
$sql .= ' AND s.rowid = '.(int) $socid;
}
if ($search_societe) {
$sql .= natural_search('s.nom', $search_societe);
}
if ($search_montant_ht != '') {
$sql .= natural_search('f.total_ht', $search_montant_ht, 1);
}
if ($search_montant_vat != '') {
$sql .= natural_search('f.total_tva', $search_montant_vat, 1);
}
if ($search_montant_ttc != '') {
$sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
}
if (!empty($search_payment_mode) && $search_payment_mode != '-1') {
$sql .= natural_search('f.fk_mode_reglement', $search_payment_mode, 1);
}
if (!empty($search_payment_term) && $search_payment_term != '-1') {
$sql .= natural_search('f.fk_cond_reglement', $search_payment_term, 1);
}
if ($search_recurring == '1') {
$sql .= ' AND f.frequency > 0';
}
if ($search_recurring == '0') {
$sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
}
if ($search_frequency != '') {
$sql .= natural_search('f.frequency', $search_frequency, 1);
}
if ($search_unit_frequency != '') {
$sql .= ' AND f.frequency > 0'.natural_search('f.unit_frequency', $search_unit_frequency);
}
if ($search_status != '' && $search_status >= -1) {
if ($search_status == 0) {
$sql .= ' AND frequency = 0 AND suspended = 0';
}
if ($search_status == 1) {
$sql .= ' AND frequency != 0 AND suspended = 0';
}
if ($search_status == -1) {
$sql .= ' AND suspended = 1';
}
}
if ($search_date_start) {
$sql .= " AND f.date_last_gen >= '".$db->idate($search_date_start)."'";
}
if ($search_date_end) {
$sql .= " AND f.date_last_gen <= '".$db->idate($search_date_end)."'";
}
if ($search_date_when_start) {
$sql .= " AND f.date_when >= '".$db->idate($search_date_when_start)."'";
}
if ($search_date_when_end) {
$sql .= " AND f.date_when <= '".$db->idate($search_date_when_end)."'";
}
$tmpsortfield = $sortfield;
if ($tmpsortfield == 'recurring') {
$tmpsortfield = 'f.frequency';
}
$sql .= $db->order($tmpsortfield, $sortorder);
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
}
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($socid > 0) {
$param .= '&socid='.urlencode($socid);
}
if ($search_date_startday) {
$param .= '&search_date_startday='.urlencode($search_date_startday);
}
if ($search_date_startmonth) {
$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
}
if ($search_date_startyear) {
$param .= '&search_date_startyear='.urlencode($search_date_startyear);
}
if ($search_date_endday) {
$param .= '&search_date_endday='.urlencode($search_date_endday);
}
if ($search_date_endmonth) {
$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
}
if ($search_date_endyear) {
$param .= '&search_date_endyear='.urlencode($search_date_endyear);
}
if ($search_date_when_startday) {
$param .= '&search_date_when_startday='.urlencode($search_date_when_startday);
}
if ($search_date_when_startmonth) {
$param .= '&search_date_when_startmonth='.urlencode($search_date_when_startmonth);
}
if ($search_date_when_startyear) {
$param .= '&search_date_when_startyear='.urlencode($search_date_when_startyear);
}
if ($search_date_when_endday) {
$param .= '&search_date_when_endday='.urlencode($search_date_when_endday);
}
if ($search_date_when_endmonth) {
$param .= '&search_date_when_endmonth='.urlencode($search_date_when_endmonth);
}
if ($search_date_when_endyear) {
$param .= '&search_date_when_endyear='.urlencode($search_date_when_endyear);
}
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
if ($search_societe) {
$param .= '&search_societe='.urlencode($search_societe);
}
if ($search_montant_ht != '') {
$param .= '&search_montant_ht='.urlencode($search_montant_ht);
}
if ($search_montant_vat != '') {
$param .= '&search_montant_vat='.urlencode($search_montant_vat);
}
if ($search_montant_ttc != '') {
$param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
}
if ($search_payment_mode != '') {
$param .= '&search_payment_mode='.urlencode($search_payment_mode);
}
if ($search_payment_term != '') {
$param .= '&search_payment_term='.urlencode($search_payment_term);
}
if ($search_recurring != '' && $search_recurring != '-1') {
$param .= '&search_recurring='.urlencode($search_recurring);
}
if ($search_frequency > 0) {
$param .= '&search_frequency='.urlencode($search_frequency);
}
if ($search_unit_frequency != '') {
$param .= '&search_unit_frequency='.urlencode($search_unit_frequency);
}
if ($search_status != '') {
$param .= '&search_status='.urlencode($search_status);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
$massactionbutton = $form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
//$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print '<input type="hidden" name="search_status" value="'.$search_status.'">';
$title = $langs->trans("RepeatableSupplierInvoices");
print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bill', 0, '', '', $limit, 0, 0, 1);
print '<span class="opacitymedium">'.$langs->trans("ToCreateAPredefinedSupplierInvoice", $langs->transnoentitiesnoconv("ChangeIntoRepeatableInvoice")).'</span><br><br>';
$i = 0;
$moreforfilter = '';
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
// Filters lines
print '<tr class="liste_titre_filter">';
// Ref
if (!empty($arrayfields['f.titre']['checked'])) {
print '<td class="liste_titre left">';
print '<input class="flat maxwidth100" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
print '</td>';
}
// Thirdparty
if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="liste_titre left"><input class="flat" type="text" size="8" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
}
if (!empty($arrayfields['f.total_ht']['checked'])) {
// Amount net
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
print '</td>';
}
if (!empty($arrayfields['f.total_tva']['checked'])) {
// Amount Vat
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
print '</td>';
}
if (!empty($arrayfields['f.total_ttc']['checked'])) {
// Amount
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
print '</td>';
}
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
// Payment term
print '<td class="liste_titre right">';
$form->select_conditions_paiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
print "</td>";
}
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
// Payment mode
print '<td class="liste_titre right">';
$form->select_types_paiements($search_payment_mode, 'search_payment_mode', '', 0, 1, 1, 0, 1, 'maxwidth100');
print '</td>';
}
if (!empty($arrayfields['recurring']['checked'])) {
// Recurring or not
print '<td class="liste_titre center">';
print $form->selectyesno('search_recurring', $search_recurring, 1, false, 1);
print '</td>';
}
if (!empty($arrayfields['f.frequency']['checked'])) {
// Recurring or not
print '<td class="liste_titre center">';
print '<input class="flat" type="text" size="1" name="search_frequency" value="'.dol_escape_htmltag($search_frequency).'">';
print '</td>';
}
if (!empty($arrayfields['f.unit_frequency']['checked'])) {
// Frequency unit
print '<td class="liste_titre center">';
print '<input class="flat" type="text" size="1" name="search_unit_frequency" value="'.dol_escape_htmltag($search_unit_frequency).'">';
print '</td>';
}
if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
// Nb generation
print '<td class="liste_titre" align="center">';
print '</td>';
}
// Date invoice
if (!empty($arrayfields['f.date_last_gen']['checked'])) {
print '<td class="liste_titre center">';
print '<div class="nowrap">';
print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
print '</div>';
print '<div class="nowrap">';
print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
print '</div>';
print '</td>';
}
// Date next generation
if (!empty($arrayfields['f.date_when']['checked'])) {
print '<td class="liste_titre center">';
print '<div class="nowrap">';
print $form->selectDate($search_date_when_start ? $search_date_when_start : -1, 'search_date_when_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
print '</div>';
print '<div class="nowrap">';
print $form->selectDate($search_date_when_end ? $search_date_when_end : -1, 'search_date_when_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
print '</div>';
print '</td>';
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields);
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// User creation
if (!empty($arrayfields['f.fk_user_author']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// User modification
if (!empty($arrayfields['f.fk_user_modif']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Date creation
if (!empty($arrayfields['f.datec']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Date modification
if (!empty($arrayfields['f.tms']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Action column
print '<td class="liste_titre" align="middle">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
print "</tr>\n";
print '<tr class="liste_titre">';
if (!empty($arrayfields['f.titre']['checked'])) {
print_liste_field_titre($arrayfields['f.titre']['label'], $_SERVER['PHP_SELF'], "f.titre", "", $param, "", $sortfield, $sortorder);
}
if (!empty($arrayfields['s.nom']['checked'])) {
print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], "s.nom", "", $param, "", $sortfield, $sortorder);
}
if (!empty($arrayfields['f.total_ht']['checked'])) {
print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], "f.total_ht", "", $param, 'class="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.total_tva']['checked'])) {
print_liste_field_titre($arrayfields['f.total_tva']['label'], $_SERVER['PHP_SELF'], "f.total_tva", "", $param, 'class="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.total_ttc']['checked'])) {
print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['recurring']['checked'])) {
print_liste_field_titre($arrayfields['recurring']['label'], $_SERVER['PHP_SELF'], "recurring", "", $param, 'class="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.frequency']['checked'])) {
print_liste_field_titre($arrayfields['f.frequency']['label'], $_SERVER['PHP_SELF'], "f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.unit_frequency']['checked'])) {
print_liste_field_titre($arrayfields['f.unit_frequency']['label'], $_SERVER['PHP_SELF'], "f.unit_frequency", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
print_liste_field_titre($arrayfields['f.nb_gen_done']['label'], $_SERVER['PHP_SELF'], "f.nb_gen_done", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.date_last_gen']['checked'])) {
print_liste_field_titre($arrayfields['f.date_last_gen']['label'], $_SERVER['PHP_SELF'], "f.date_last_gen", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.date_when']['checked'])) {
print_liste_field_titre($arrayfields['f.date_when']['label'], $_SERVER['PHP_SELF'], "f.date_when", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.fk_user_author']['checked'])) {
print_liste_field_titre($arrayfields['f.fk_user_author']['label'], $_SERVER['PHP_SELF'], "f.fk_user_author", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.fk_user_modif']['checked'])) {
print_liste_field_titre($arrayfields['f.fk_user_modif']['label'], $_SERVER['PHP_SELF'], "f.fk_user_modif", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.datec']['checked'])) {
print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER['PHP_SELF'], "f.datec", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.tms']['checked'])) {
print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER['PHP_SELF'], "f.tms", "", $param, 'align="center"', $sortfield, $sortorder);
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
if (!empty($arrayfields['status']['checked'])) {
print_liste_field_titre($arrayfields['status']['label'], $_SERVER['PHP_SELF'], "f.suspended,f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
}
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'center maxwidthsearch ');
print "</tr>\n";
if ($num > 0) {
$i = 0;
$totalarray = array();
$totalarray['nbfield'] = 0;
$totalarray['val']['f.total_ht'] = 0;
$totalarray['val']['f.total_tva'] = 0;
$totalarray['val']['f.total_ttc'] = 0;
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql);
if (empty($objp)) {
break;
}
$companystatic->id = $objp->socid;
$companystatic->name = $objp->name;
$supplierinvoicerectmp->id = !empty($objp->id) ? $objp->id : $objp->facid;
$supplierinvoicerectmp->frequency = $objp->frequency;
$supplierinvoicerectmp->suspended = $objp->suspended;
$supplierinvoicerectmp->unit_frequency = $objp->unit_frequency;
$supplierinvoicerectmp->nb_gen_max = $objp->nb_gen_max;
$supplierinvoicerectmp->nb_gen_done = $objp->nb_gen_done;
$supplierinvoicerectmp->ref = $objp->title;
$supplierinvoicerectmp->total_ht = $objp->total_ht;
$supplierinvoicerectmp->total_tva = $objp->total_tva;
$supplierinvoicerectmp->total_ttc = $objp->total_ttc;
print '<tr class="oddeven">';
if (!empty($arrayfields['f.titre']['checked'])) {
print '<td class="nowrap tdoverflowmax200">';
print $supplierinvoicerectmp->getNomUrl(1);
print "</a>";
print "</td>\n";
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="tdoverflowmax200">'.$companystatic->getNomUrl(1, 'customer').'</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.total_ht']['checked'])) {
print '<td class="nowrap right amount">'.price($objp->total_ht).'</td>'."\n";
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
}
$totalarray['val']['f.total_ht'] += $objp->total_ht;
}
if (!empty($arrayfields['f.total_tva']['checked'])) {
print '<td class="nowrap right amount">'.price($objp->total_tva).'</td>'."\n";
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'f.total_tva';
}
$totalarray['val']['f.total_tva'] += $objp->total_tva;
}
if (!empty($arrayfields['f.total_ttc']['checked'])) {
print '<td class="nowrap right amount">'.price($objp->total_ttc).'</td>'."\n";
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
}
$totalarray['val']['f.total_ttc'] += $objp->total_ttc;
}
// Payment term
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
print '<td class="right">';
$form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none');
print '</td>'."\n";
if (!$i) {
$totalarray['nbfield']++;
}
}
// Payment mode
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
print '<td class="right">';
$form->form_modes_reglement('', $objp->fk_mode_reglement, 'none');
print '</td>'."\n";
if (!$i) {
$totalarray['nbfield']++;
}
}
// Is it a recurring invoice
if (!empty($arrayfields['recurring']['checked'])) {
print '<td class="center">'.($objp->frequency ? img_picto($langs->trans("Frequency").': '.$objp->frequency.' '.$objp->unit_frequency, 'recurring', 'class="opacitymedium"').' ' : '').yn($objp->frequency ? 1 : 0).'</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.frequency']['checked'])) {
print '<td class="center">'.($objp->frequency > 0 ? $objp->frequency : '').'</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.unit_frequency']['checked'])) {
print '<td class="center">'.($objp->frequency > 0 ? $objp->unit_frequency : '').'</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
print '<td class="center">';
print ($objp->frequency > 0 ? $objp->nb_gen_done.($objp->nb_gen_max > 0 ? ' / '.$objp->nb_gen_max : '') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date last generation
if (!empty($arrayfields['f.date_last_gen']['checked'])) {
print '<td class="center">';
print ($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen), 'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date next generation
if (!empty($arrayfields['f.date_when']['checked'])) {
print '<td class="center">';
print '<div class="nowraponall">';
print ($objp->frequency ? ($supplierinvoicerectmp->isMaxNbGenReached() ? '<strike>' : '').dol_print_date($db->jdate($objp->date_when), 'day').($supplierinvoicerectmp->isMaxNbGenReached() ? '</strike>' : '') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
if (!$supplierinvoicerectmp->isMaxNbGenReached()) {
if (!$objp->suspended && $objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) {
print img_warning($langs->trans("Late"));
}
} else {
print img_info($langs->trans("MaxNumberOfGenerationReached"));
}
print '</div>';
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.fk_user_author']['checked'])) {
print '<td class="center tdoverflowmax150">';
if ($objp->fk_user_author > 0) {
$tmpuser->fetch($objp->fk_user_author);
print $tmpuser->getNomUrl(1);
}
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.fk_user_modif']['checked'])) {
print '<td class="center tdoverflowmax150">';
if ($objp->fk_user_author > 0) {
$tmpuser->fetch($objp->fk_user_author);
print $tmpuser->getNomUrl(1);
}
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.datec']['checked'])) {
print '<td class="center">';
print dol_print_date($db->jdate($objp->datec), 'dayhour');
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.tms']['checked'])) {
print '<td class="center">';
print dol_print_date($db->jdate($objp->tms), 'dayhour');
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
$obj = $objp;
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$objp, 'i'=>$i, 'totalarray'=>&$totalarray);
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Status
if (!empty($arrayfields['status']['checked'])) {
print '<td class="center">';
print $supplierinvoicerectmp->getLibStatut(3, 0);
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Action column
print '<td class="center tdoverflowmax125">';
if ($user->rights->facture->creer && empty($supplierinvoicerectmp->suspended)) {
if ($supplierinvoicerectmp->isMaxNbGenReached()) {
print $langs->trans("MaxNumberOfGenerationReached");
} elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) {
print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;socid='.$objp->socid.'&amp;fac_rec='.$objp->facid.'">';
print img_picto($langs->trans("CreateBill"), 'add', 'class="paddingrightonly"');
print $langs->trans("CreateBill").'</a>';
} else {
print $form->textwithpicto('', $langs->trans("DateIsNotEnough"));
}
} else {
print "&nbsp;";
}
if (!$i) {
$totalarray['nbfield']++;
}
print "</td>";
print "</tr>\n";
$i++;
}
} else {
$colspan = 1;
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}
// Show total line
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
print "</table>";
print "</div>";
print "</form>";
$db->free($resql);
} else {
dol_print_error($db);
}
// End of page
llxFooter();
$db->close();

View File

@ -96,4 +96,130 @@ CREATE TABLE llx_stock_mouvement_extrafields (
import_key varchar(14)
)ENGINE=innodb;
-- Facture fourn rec
CREATE TABLE llx_facture_fourn_rec
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
titre varchar(200) NOT NULL,
ref_supplier varchar(180) NOT NULL,
entity integer DEFAULT 1 NOT NULL,
fk_soc integer NOT NULL,
datec datetime,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
suspended integer DEFAULT 0,
libelle varchar(255),
amount double(24, 8) DEFAULT 0 NOT NULL,
remise real DEFAULT 0,
vat_src_code varchar(10) DEFAULT '',
localtax1 double(24,8) DEFAULT 0,
localtax2 double(24,8) DEFAULT 0,
total_ht double(24,8) DEFAULT 0,
total_tva double(24,8) DEFAULT 0,
total_ttc double(24,8) DEFAULT 0,
fk_user_author integer,
fk_user_modif integer,
fk_projet integer,
fk_account integer,
fk_cond_reglement integer,
fk_mode_reglement integer,
date_lim_reglement date,
note_private text,
note_public text,
modelpdf varchar(255),
fk_multicurrency integer,
multicurrency_code varchar(3),
multicurrency_tx double(24,8) DEFAULT 1,
multicurrency_total_ht double(24,8) DEFAULT 0,
multicurrency_total_tva double(24,8) DEFAULT 0,
multicurrency_total_ttc double(24,8) DEFAULT 0,
usenewprice integer DEFAULT 0,
frequency integer,
unit_frequency varchar(2) DEFAULT 'm',
date_when datetime DEFAULT NULL,
date_last_gen datetime DEFAULT NULL,
nb_gen_done integer DEFAULT NULL,
nb_gen_max integer DEFAULT NULL,
auto_validate integer DEFAULT 0,
generate_pdf integer DEFAULT 1
)ENGINE=innodb;
ALTER TABLE llx_facture_fourn_rec ADD UNIQUE INDEX uk_facture_fourn_rec_ref (titre, entity);
ALTER TABLE llx_facture_fourn_rec ADD UNIQUE INDEX uk_facture_fourn_rec_ref_supplier (ref_supplier, fk_soc, entity);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_date_lim_reglement (date_lim_reglement);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_fk_soc (fk_soc);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_fk_user_author (fk_user_author);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_fk_projet (fk_projet);
ALTER TABLE llx_facture_fourn_rec ADD CONSTRAINT fk_facture_fourn_rec_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
ALTER TABLE llx_facture_fourn_rec ADD CONSTRAINT fk_facture_fourn_rec_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
ALTER TABLE llx_facture_fourn_rec ADD CONSTRAINT fk_facture_fourn_rec_fk_projet FOREIGN KEY (fk_projet) REFERENCES llx_projet (rowid);
CREATE TABLE llx_facture_fourn_rec_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fk_object integer NOT NULL,
import_key varchar(14) -- import key
) ENGINE=innodb;
ALTER TABLE llx_facture_fourn_rec_extrafields ADD INDEX idx_facture_fourn_rec_extrafields (fk_object);
CREATE TABLE llx_facture_fourn_det_rec
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_facture_fourn integer NOT NULL,
fk_parent_line integer NULL,
fk_product integer NULL,
ref varchar(50),
label varchar(255) DEFAULT NULL,
description text,
pu_ht double(24,8),
pu_ttc double(24,8),
qty real,
remise_percent real DEFAULT 0,
fk_remise_except integer NULL,
vat_src_code varchar(10) DEFAULT '',
tva_tx double(7,4),
localtax1_tx double(7,4) DEFAULT 0,
localtax1_type varchar(10) NULL,
localtax2_tx double(7,4) DEFAULT 0,
localtax2_type varchar(10) NULL,
total_ht double(24,8),
total_tva double(24,8),
total_localtax1 double(24,8) DEFAULT 0,
total_localtax2 double(24,8) DEFAULT 0,
total_ttc double(24,8),
product_type integer DEFAULT 0,
date_start integer DEFAULT NULL,
date_end integer DEFAULT NULL,
info_bits integer DEFAULT 0,
special_code integer UNSIGNED DEFAULT 0,
rang integer DEFAULT 0,
fk_unit integer DEFAULT NULL,
import_key varchar(14),
fk_user_author integer,
fk_user_modif integer,
fk_multicurrency integer,
multicurrency_code varchar(3),
multicurrency_subprice double(24,8) DEFAULT 0,
multicurrency_total_ht double(24,8) DEFAULT 0,
multicurrency_total_tva double(24,8) DEFAULT 0,
multicurrency_total_ttc double(24,8) DEFAULT 0
)ENGINE=innodb;
ALTER TABLE llx_facture_fourn_det_rec ADD CONSTRAINT fk_facture_fourn_det_rec_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
CREATE TABLE llx_facture_fourn_det_rec_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fk_object integer NOT NULL, -- object id
import_key varchar(14) -- import key
)ENGINE=innodb;
ALTER TABLE llx_facture_fourn_det_rec_extrafields ADD INDEX idx_facture_fourn_det_rec_extrafields (fk_object);
ALTER TABLE llx_facture_fourn ADD COLUMN fk_fac_rec_source integer;
ALTER TABLE llx_mrp_mo ADD COLUMN fk_parent_line integer;

View File

@ -61,6 +61,7 @@ create table llx_facture_fourn
fk_user_valid integer, -- user validating
fk_user_closing integer, -- user closing
fk_fac_rec_source integer, -- facture rec source
fk_facture_source integer, -- facture origine si facture avoir
fk_projet integer, -- projet auquel est associee la facture

View File

@ -0,0 +1,20 @@
-- ========================================================================
-- Copyright (C) 2017 ATM-CONSULTING <contact@atm-consulting.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- ===================================================================
ALTER TABLE llx_facture_fourn_det_rec_extrafields ADD INDEX llx_facture_fourn_det_rec_extrafields (fk_object);

View File

@ -0,0 +1,24 @@
-- ===================================================================
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- ===================================================================
create table llx_facture_fourn_det_rec_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fk_object integer NOT NULL, -- object id
import_key varchar(14) -- import key
)ENGINE=innodb;

View File

@ -0,0 +1,18 @@
-- ===================================================================
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- ===================================================================
ALTER TABLE llx_facture_fourn_det_rec ADD CONSTRAINT fk_facture_fourn_det_rec_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);

View File

@ -0,0 +1,61 @@
-- ===================================================================
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- ===================================================================
create table llx_facture_fourn_det_rec
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_facture_fourn integer NOT NULL,
fk_parent_line integer NULL,
fk_product integer NULL,
ref varchar(50), -- supplier product ref
label varchar(255) DEFAULT NULL,
description text,
pu_ht double(24,8), -- unit price excluding tax
pu_ttc double(24,8), -- unit price with tax
qty real, -- quantity of product/service
remise_percent real DEFAULT 0, -- % de la remise ligne (exemple 20%)
fk_remise_except integer NULL, -- Lien vers table des remises fixes
vat_src_code varchar(10) DEFAULT '', -- Vat code used as source of vat fields. Not strict foreign key here.
tva_tx double(7,4), -- taux tva
localtax1_tx double(7,4) DEFAULT 0, -- localtax1 rate
localtax1_type varchar(10) NULL, -- localtax1 type
localtax2_tx double(7,4) DEFAULT 0, -- localtax2 rate
localtax2_type varchar(10) NULL, -- localtax2 type
total_ht double(24,8), -- Total HT de la ligne toute quantity et incluant remise ligne et globale
total_tva double(24,8), -- Total TVA de la ligne toute quantity et incluant remise ligne et globale
total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 for total quantity of line
total_localtax2 double(24,8) DEFAULT 0, -- total LocalTax2 for total quantity of line
total_ttc double(24,8), -- Total TTC de la ligne toute quantity et incluant remise ligne et globale
product_type integer DEFAULT 0,
date_start integer DEFAULT NULL, -- date debut si service
date_end integer DEFAULT NULL, -- date fin si service
info_bits integer DEFAULT 0, -- TVA NPR ou non
special_code integer UNSIGNED DEFAULT 0, -- code for special lines
rang integer DEFAULT 0, -- ordre d'affichage
fk_unit integer DEFAULT NULL,
import_key varchar(14),
fk_user_author integer, -- user making creation
fk_user_modif integer, -- user making last change
fk_multicurrency integer,
multicurrency_code varchar(3),
multicurrency_subprice double(24,8) DEFAULT 0,
multicurrency_total_ht double(24,8) DEFAULT 0,
multicurrency_total_tva double(24,8) DEFAULT 0,
multicurrency_total_ttc double(24,8) DEFAULT 0
)ENGINE=innodb;

View File

@ -0,0 +1,19 @@
-- ===================================================================
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- ===================================================================
ALTER TABLE llx_facture_fourn_rec_extrafields ADD INDEX idx_facture_fourn_rec_extrafields (fk_object);

View File

@ -0,0 +1,7 @@
create table llx_facture_fourn_rec_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fk_object integer NOT NULL,
import_key varchar(14) -- import key
) ENGINE=innodb;

View File

@ -0,0 +1,29 @@
-- ============================================================================
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- ============================================================================
ALTER TABLE llx_facture_fourn_rec ADD UNIQUE INDEX uk_facture_fourn_rec_ref (ref, entity);
ALTER TABLE llx_facture_fourn_rec ADD UNIQUE INDEX uk_facture_fourn_rec_ref_supplier (ref_supplier, fk_soc, entity);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_date_lim_reglement (date_lim_reglement);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_fk_soc (fk_soc);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_fk_user_author (fk_user_author);
ALTER TABLE llx_facture_fourn_rec ADD INDEX idx_facture_fourn_rec_fk_projet (fk_projet);
ALTER TABLE llx_facture_fourn_rec ADD CONSTRAINT fk_facture_fourn_rec_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
ALTER TABLE llx_facture_fourn_rec ADD CONSTRAINT fk_facture_fourn_rec_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
ALTER TABLE llx_facture_fourn_rec ADD CONSTRAINT fk_facture_fourn_rec_fk_projet FOREIGN KEY (fk_projet) REFERENCES llx_projet (rowid);

View File

@ -0,0 +1,77 @@
-- ===========================================================================
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- ===========================================================================
create table llx_facture_fourn_rec
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
titre varchar(200) NOT NULL,
ref_supplier varchar(180) NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id
fk_soc integer NOT NULL,
datec datetime, -- date de creation
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- last modification date
suspended integer DEFAULT 0, -- 1=suspended
libelle varchar(255),
amount double(24, 8) DEFAULT 0 NOT NULL,
remise real DEFAULT 0,
vat_src_code varchar(10) DEFAULT '', -- Vat code used as source of vat fields. Not strict foreign key here.
localtax1 double(24,8) DEFAULT 0,
localtax2 double(24,8) DEFAULT 0,
total_ht double(24,8) DEFAULT 0,
total_tva double(24,8) DEFAULT 0,
total_ttc double(24,8) DEFAULT 0,
fk_user_author integer, -- user creating
fk_user_modif integer, -- user making last change
fk_projet integer, -- projet auquel est associe la facture
fk_account integer, -- bank account
fk_cond_reglement integer, -- condition de reglement (30 jours, fin de mois ...)
fk_mode_reglement integer, -- mode de reglement (CHQ, VIR, ...)
date_lim_reglement date, -- date limite de reglement
note_private text,
note_public text,
modelpdf varchar(255),
fk_multicurrency integer,
multicurrency_code varchar(3),
multicurrency_tx double(24,8) DEFAULT 1,
multicurrency_total_ht double(24,8) DEFAULT 0,
multicurrency_total_tva double(24,8) DEFAULT 0,
multicurrency_total_ttc double(24,8) DEFAULT 0,
-- Fields linked to the recurring behavior
usenewprice integer DEFAULT 0, -- update invoice with current price of product instead of recorded price
frequency integer, -- frequency (for example: 3 for every 3 month)
unit_frequency varchar(2) DEFAULT 'm', -- 'm' for month (date_when must be a day <= 28), 'y' for year, ...
date_when datetime DEFAULT NULL, -- date for next gen (when an invoice is generated, this field must be updated with next date)
date_last_gen datetime DEFAULT NULL, -- date for last gen (date with last successfull generation of invoice)
nb_gen_done integer DEFAULT NULL, -- nb of generation done (when an invoice is generated, this field must incremented)
nb_gen_max integer DEFAULT NULL, -- maximum number of generation
auto_validate integer DEFAULT 0, -- 0 to create in draft, 1 to create and validate the new invoice
generate_pdf integer DEFAULT 1 -- 0 disable pdf, 1 to generate pdf
)ENGINE=innodb;

View File

@ -9,6 +9,7 @@ ErrorBadMXDomain=Email %s seems incorrect (domain has no valid MX record)
ErrorBadUrl=Url %s is incorrect
ErrorBadValueForParamNotAString=Bad value for your parameter. It appends generally when translation is missing.
ErrorRefAlreadyExists=Reference <b>%s</b> already exists.
ErrorTitleAlreadyExists=Title <b>%s</b> already exists.
ErrorLoginAlreadyExists=Login %s already exists.
ErrorGroupAlreadyExists=Group %s already exists.
ErrorEmailAlreadyExists=Email %s already exists.

View File

@ -47,3 +47,10 @@ BuyerName=Buyer name
AllProductServicePrices=All product / service prices
AllProductReferencesOfSupplier=All references of vendor
BuyingPriceNumShort=Vendor prices
RepeatableSupplierInvoice=Template supplier invoice
RepeatableSupplierInvoices=Template supplier invoices
RepeatableSupplierInvoicesList=Template supplier invoices
RecurringSupplierInvoices=Recurring supplier invoices
ToCreateAPredefinedSupplierInvoice=In order to create template supplier invoice, you must create a standard invoice, then, without validating it, click on the "%s" button.
GeneratedFromSupplierTemplate=Generated from supplier invoice template %s
SupplierInvoiceGeneratedFromTemplate=Supplier invoice %s Generated from supplier invoice template %s

View File

@ -8,7 +8,7 @@ ErrorBadEMail=L'email '%s' est invalide
ErrorBadMXDomain=L'email %s semble incorrect (domaine n'a pas d'enregistrement MX valide)
ErrorBadUrl=L'URL '%s' est invalide
ErrorBadValueForParamNotAString=Mauvaise valeur de paramètre. Ceci arrive lors d'une tentative de traduction d'une clé non renseignée.
ErrorRefAlreadyExists=Le référence <b>%s</b> existe déjà.
ErrorRefAlreadyExists=La référence <b>%s</b> existe déjà.
ErrorLoginAlreadyExists=L'identifiant %s existe déjà.
ErrorGroupAlreadyExists=Le groupe %s existe déjà.
ErrorEmailAlreadyExists=L'e-mail %s existe déjà.

View File

@ -46,4 +46,4 @@ ReputationForThisProduct=Réputation
BuyerName=Nom de l'acheteur
AllProductServicePrices=Tous les prix du produits / service
AllProductReferencesOfSupplier=Toutes les références du fournisseur
BuyingPriceNumShort=Prix fournisseurs
BuyingPriceNumShort=Prix fournisseurs