Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2017-11-11 17:49:51 +01:00
commit b5d63de708
18 changed files with 289 additions and 46 deletions

View File

@ -77,11 +77,6 @@ $model_option = array (
'label' => 'ACCOUNTING_EXPORT_DATE', 'label' => 'ACCOUNTING_EXPORT_DATE',
'param' => '', 'param' => '',
), ),
//'ACCOUNTING_EXPORT_PIECE',
//'ACCOUNTING_EXPORT_GLOBAL_ACCOUNT',
//'ACCOUNTING_EXPORT_LABEL',
//'ACCOUNTING_EXPORT_AMOUNT',
//'ACCOUNTING_EXPORT_DEVISE',
); );
/* /*
@ -143,7 +138,6 @@ $form = new Form($db);
// $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>'; // $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup'); print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup');
$head = admin_accounting_prepare_head();
print "\n".'<script type="text/javascript" language="javascript">'."\n"; print "\n".'<script type="text/javascript" language="javascript">'."\n";
print 'jQuery(document).ready(function () {'."\n"; print 'jQuery(document).ready(function () {'."\n";
@ -193,7 +187,6 @@ print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
dol_fiche_head($head, 'export', $langs->trans("Configuration"), -1, 'technic');
/* /*
* Main Options * Main Options

View File

@ -547,9 +547,9 @@ class AccountancyExport
$tab = array(); $tab = array();
// export configurable // export configurable
$date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE); $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
$tab[] = $line->piece_num;
$tab[] = $date; $tab[] = $date;
$tab[] = $line->doc_ref; $tab[] = $line->doc_ref;
$tab[] = $line->piece_num;
$tab[] = $line->label_operation; $tab[] = $line->label_operation;
$tab[] = length_accountg($line->numero_compte); $tab[] = length_accountg($line->numero_compte);
$tab[] = length_accounta($line->subledger_account); $tab[] = length_accounta($line->subledger_account);

View File

@ -80,6 +80,7 @@ $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
$search_country_id = GETPOST('search_country_id','int'); $search_country_id = GETPOST('search_country_id','int');
if($search_country_id == '') $search_country_id = $mysoc->country_id;
$search_code = GETPOST('search_code','alpha'); $search_code = GETPOST('search_code','alpha');
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context

View File

@ -208,6 +208,68 @@ class Setup extends DolibarrApi
return $this->_cleanObjectDatas($country); return $this->_cleanObjectDatas($country);
} }
/**
* Get the list of delivery times.
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number {@min 0}
* @param int $active Delivery times is active or not {@min 0} {@max 1}
* @param string $sqlfilters SQL criteria to filter with.
*
* @url GET dictionary/availability
*
* @return array [List of availability]
*
* @throws 400 RestException
* @throws 200 OK
*/
function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
{
$list = array();
$sql = "SELECT rowid, code, label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_availability as t";
$sql.= " WHERE t.active = ".$active;
// Add sql filters
if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
$sql.= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
$sql .= $this->db->plimit($limit, $offset);
}
$result = $this->db->query($sql);
if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
for ($i = 0; $i < $min; $i++) {
$list[] = $this->db->fetch_object($result);
}
} else {
throw new RestException(400, $this->db->lasterror());
}
return $list;
}
/** /**
* Clean sensible object datas * Clean sensible object datas
* *

View File

@ -6,6 +6,7 @@
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -107,6 +108,7 @@ class FactureRec extends CommonInvoice
$this->nb_gen_done=0; $this->nb_gen_done=0;
$this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max; $this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max;
$this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate; $this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate;
$this->generate_pdf = empty($this->generate_pdf)?0:$this->generate_pdf;
$this->db->begin(); $this->db->begin();
@ -127,6 +129,7 @@ class FactureRec extends CommonInvoice
$sql.= ", remise"; $sql.= ", remise";
$sql.= ", note_private"; $sql.= ", note_private";
$sql.= ", note_public"; $sql.= ", note_public";
$sql.= ", modelpdf";
$sql.= ", fk_user_author"; $sql.= ", fk_user_author";
$sql.= ", fk_projet"; $sql.= ", fk_projet";
$sql.= ", fk_account"; $sql.= ", fk_account";
@ -140,6 +143,7 @@ class FactureRec extends CommonInvoice
$sql.= ", nb_gen_done"; $sql.= ", nb_gen_done";
$sql.= ", nb_gen_max"; $sql.= ", nb_gen_max";
$sql.= ", auto_validate"; $sql.= ", auto_validate";
$sql.= ", generate_pdf";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= "'".$this->db->escape($this->titre)."'"; $sql.= "'".$this->db->escape($this->titre)."'";
$sql.= ", ".$facsrc->socid; $sql.= ", ".$facsrc->socid;
@ -149,6 +153,7 @@ class FactureRec extends CommonInvoice
$sql.= ", ".(!empty($facsrc->remise)?$this->remise:'0'); $sql.= ", ".(!empty($facsrc->remise)?$this->remise:'0');
$sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL"); $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
$sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL"); $sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
$sql.= ", ".(!empty($this->modelpdf)?("'".$this->db->escape($this->modelpdf)."'"):"NULL");
$sql.= ", '".$this->db->escape($user->id)."'"; $sql.= ", '".$this->db->escape($user->id)."'";
$sql.= ", ".(! empty($facsrc->fk_project)?"'".$facsrc->fk_project."'":"null"); $sql.= ", ".(! empty($facsrc->fk_project)?"'".$facsrc->fk_project."'":"null");
$sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null"); $sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null");
@ -162,6 +167,7 @@ class FactureRec extends CommonInvoice
$sql.= ", ".$this->nb_gen_done; $sql.= ", ".$this->nb_gen_done;
$sql.= ", ".$this->nb_gen_max; $sql.= ", ".$this->nb_gen_max;
$sql.= ", ".$this->auto_validate; $sql.= ", ".$this->auto_validate;
$sql.= ", ".$this->generate_pdf;
$sql.= ")"; $sql.= ")";
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -276,9 +282,11 @@ class FactureRec extends CommonInvoice
$sql.= ', f.remise_percent, f.remise_absolue, f.remise'; $sql.= ', f.remise_percent, f.remise_absolue, f.remise';
$sql.= ', f.date_lim_reglement as dlr'; $sql.= ', f.date_lim_reglement as dlr';
$sql.= ', f.note_private, f.note_public, f.fk_user_author'; $sql.= ', f.note_private, f.note_public, f.fk_user_author';
$sql.= ', f.modelpdf';
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet'; $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet';
$sql.= ', f.fk_account'; $sql.= ', f.fk_account';
$sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate'; $sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate';
$sql.= ', f.generate_pdf';
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
//$sql.= ', el.fk_source'; //$sql.= ', el.fk_source';
@ -336,7 +344,7 @@ class FactureRec extends CommonInvoice
$this->note_private = $obj->note_private; $this->note_private = $obj->note_private;
$this->note_public = $obj->note_public; $this->note_public = $obj->note_public;
$this->user_author = $obj->fk_user_author; $this->user_author = $obj->fk_user_author;
$this->modelpdf = $obj->model_pdf; $this->modelpdf = $obj->modelpdf;
$this->rang = $obj->rang; $this->rang = $obj->rang;
$this->special_code = $obj->special_code; $this->special_code = $obj->special_code;
$this->frequency = $obj->frequency; $this->frequency = $obj->frequency;
@ -347,6 +355,7 @@ class FactureRec extends CommonInvoice
$this->nb_gen_max = $obj->nb_gen_max; $this->nb_gen_max = $obj->nb_gen_max;
$this->usenewprice = $obj->usenewprice; $this->usenewprice = $obj->usenewprice;
$this->auto_validate = $obj->auto_validate; $this->auto_validate = $obj->auto_validate;
$this->generate_pdf = $obj->generate_pdf;
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
@ -948,6 +957,16 @@ class FactureRec extends CommonInvoice
$this->errors = $facture->errors; $this->errors = $facture->errors;
$this->error = $facture->error; $this->error = $facture->error;
$error++; $error++;
}
}
if (! $error && $facturerec->generate_pdf)
{
$result = $facture->generateDocument($facturerec->modelpdf, $langs);
if ($result <= 0)
{
$this->errors = $facture->errors;
$this->error = $facture->error;
$error++;
} }
} }
@ -1391,6 +1410,68 @@ class FactureRec extends CommonInvoice
return -1; return -1;
} }
} }
/**
* Update the auto generate documents
*
* @param int $validate 0 no document, 1 to generate document
* @return int <0 if KO, >0 if OK
*/
function setGeneratePdf($validate)
{
if (! $this->table_element)
{
dol_syslog(get_class($this)."::setGeneratePdf was called on objet with property table_element not defined",LOG_ERR);
return -1;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET generate_pdf = '.$validate;
$sql.= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
if ($this->db->query($sql))
{
$this->generate_pdf = $validate;
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Update the model for documents
*
* @param string $model model of document generator
* @return int <0 if KO, >0 if OK
*/
function setModelPdf($model)
{
if (! $this->table_element)
{
dol_syslog(get_class($this)."::setModelPdf was called on objet with property table_element not defined",LOG_ERR);
return -1;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET modelpdf = "' . $model . '"';
$sql.= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
if ($this->db->query($sql))
{
$this->modelpdf = $model;
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
} }

View File

@ -8,6 +8,7 @@
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr> * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
* Copyright (C) 2017 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -211,13 +212,14 @@ if (empty($reshook))
$object->titre = GETPOST('titre', 'alpha'); $object->titre = GETPOST('titre', 'alpha');
$object->note_private = GETPOST('note_private','none'); $object->note_private = GETPOST('note_private','none');
$object->note_public = GETPOST('note_public','none'); $object->note_public = GETPOST('note_public','none');
$object->modelpdf = GETPOST('modelpdf', 'alpha');
$object->usenewprice = GETPOST('usenewprice'); $object->usenewprice = GETPOST('usenewprice');
$object->frequency = $frequency; $object->frequency = $frequency;
$object->unit_frequency = GETPOST('unit_frequency', 'alpha'); $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
$object->nb_gen_max = $nb_gen_max; $object->nb_gen_max = $nb_gen_max;
$object->auto_validate = GETPOST('auto_validate', 'int'); $object->auto_validate = GETPOST('auto_validate', 'int');
$object->generate_pdf = GETPOST('generate_pdf', 'int');
$object->fk_project = $projectid; $object->fk_project = $projectid;
$date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
@ -346,6 +348,16 @@ if (empty($reshook))
{ {
$object->setAutoValidate(GETPOST('auto_validate', 'int')); $object->setAutoValidate(GETPOST('auto_validate', 'int'));
} }
// Set generate pdf
elseif ($action == 'setgenerate_pdf' && $user->rights->facture->creer)
{
$object->setGeneratepdf(GETPOST('generate_pdf', 'int'));
}
// Set model pdf
elseif ($action == 'setmodelpdf' && $user->rights->facture->creer)
{
$object->setModelpdf(GETPOST('modelpdf', 'alpha'));
}
// Delete line // Delete line
if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer)
@ -1040,6 +1052,13 @@ if ($action == 'create')
print "</td></tr>"; print "</td></tr>";
} }
// Model pdf
print "<tr><td>".$langs->trans('Model')."</td><td>";
include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php';
$list = ModelePDFFactures::liste_modeles($db);
print $form->selectarray('modelpdf', $list, $conf->global->FACTURE_ADDON_PDF);
print "</td></tr>";
print "</table>"; print "</table>";
dol_fiche_end(); dol_fiche_end();
@ -1075,6 +1094,12 @@ if ($action == 'create')
print $form->selectarray('auto_validate', $select, GETPOST('auto_validate')); print $form->selectarray('auto_validate', $select, GETPOST('auto_validate'));
print "</td></tr>"; print "</td></tr>";
// Auto generate document
print "<tr><td>".$langs->trans("StatusOfGeneratedDocuments")."</td><td>";
$select = array('0'=>$langs->trans('DoNotGenerateDoc'),'1'=>$langs->trans('AutoGenerateDoc'));
print $form->selectarray('generate_pdf', $select, GETPOST('generate_pdf'));
print "</td></tr>";
print "</table>"; print "</table>";
dol_fiche_end(); dol_fiche_end();
@ -1345,6 +1370,34 @@ else
print "</td>"; print "</td>";
print '</tr>'; print '</tr>';
// Model pdf
$langs->load('banks');
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans('Model');
print '<td>';
if (($action != 'editmodelpdf') && $user->rights->facture->creer && ! empty($object->brouillon))
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmodelpdf&amp;id='.$object->id.'">'.img_edit($langs->trans('SetModel'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'editmodelpdf')
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php';
$list = array();
$models = ModelePDFFactures::liste_modeles($db);
foreach ($models as $model) {
$list[] = $model . ':' . $model;
}
$select = 'select;'.implode(',', $list);
print $form->editfieldval($langs->trans("Model"), 'modelpdf', $object->modelpdf, $object, $user->rights->facture->creer, $select);
}
else
{
print $object->modelpdf;
}
print "</td>";
print '</tr>';
// Other attributes // Other attributes
$cols = 2; $cols = 2;
@ -1455,6 +1508,19 @@ else
print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select); print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select);
} }
print '</td>'; print '</td>';
// Auto generate documents
print '<tr><td>';
if ($action == 'generate_pdf' || $object->frequency > 0)
print $form->editfieldkey($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer);
else
print $langs->trans("StatusOfGeneratedDocuments");
print '</td><td>';
$select = 'select;0:'.$langs->trans('DoNotGenerateDoc').',1:'.$langs->trans('AutogenerateDoc');
if ($action == 'generate_pdf' || $object->frequency > 0)
{
print $form->editfieldval($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer, $select);
}
print '</td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';

View File

@ -1579,6 +1579,12 @@ function dol_format_address($object,$withcountry=0,$sep="\n",$outputlangs='')
$ret.="\n".$object->state; $ret.="\n".$object->state;
} }
} }
else if (in_array($object->country_code,array('IT'))) // IT: tile firstname name\n address lines \n zip (Code Departement) \n country
{
$ret .= ($ret ? $sep : '' ).$object->zip;
$ret .= ($object->town?(($object->zip?' ':'').$object->town):'');
$ret .= ($object->departement_id?(' ('.($object->departement_id).')'):'');
}
else // Other: title firstname name \n address lines \n zip town \n country else // Other: title firstname name \n address lines \n zip town \n country
{ {
$ret .= $object->zip ? (($ret ? $sep : '' ).$object->zip) : ''; $ret .= $object->zip ? (($ret ? $sep : '' ).$object->zip) : '';

View File

@ -390,8 +390,10 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO deprecated if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO deprecated
if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id); if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id);
if (! empty($sourcecompany->state_id) && !isset($sourcecompany->departement_id)) $sourcecompany->departement_id=getState($sourcecompany->state_id,'2');
if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); //TODO deprecated if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); //TODO deprecated
if (! empty($targetcompany->state_id) && empty($targetcompany->state)) $targetcompany->state=getState($targetcompany->state_id); if (! empty($targetcompany->state_id) && empty($targetcompany->state)) $targetcompany->state=getState($targetcompany->state_id);
if (! empty($targetcompany->state_id) && !isset($targetcompany->departement_id)) $targetcompany->departement_id=getState($targetcompany->state_id,'2');
$reshook=0; $reshook=0;
$stringaddress = ''; $stringaddress = '';

View File

@ -456,7 +456,7 @@ function getRandomPassword($generic=false)
$randomCode = ""; $randomCode = "";
$nbofchar = round($length/3); $nbofchar = round($length/3);
$nbofcharlast = ($length - 2*$nbofchar); $nbofcharlast = ($length - 2*$nbofchar);
var_dump($nbofchar.'-'.$nbofcharlast); //var_dump($nbofchar.'-'.$nbofcharlast);
if (function_exists('random_int')) // Cryptographic random if (function_exists('random_int')) // Cryptographic random
{ {
$max = strlen($lowercase) - 1; $max = strlen($lowercase) - 1;

View File

@ -432,7 +432,7 @@ class ProductFournisseur extends Product
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression))
{ {
$priceparser = new PriceParser($this->db); $priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($this->fk_product, $this->fk_supplier_price_expression, $this->fourn_qty, $this->fourn_tva_tx); $price_result = $priceparser->parseProductSupplier($this);
if ($price_result >= 0) { if ($price_result >= 0) {
$this->fourn_price = $price_result; $this->fourn_price = $price_result;
//recalculation of unitprice, as probably the price changed... //recalculation of unitprice, as probably the price changed...

View File

@ -528,6 +528,9 @@ ALTER TABLE llx_resource ADD UNIQUE INDEX uk_resource_ref (ref, entity);
ALTER TABLE llx_product ADD COLUMN accountancy_code_sell_intra varchar(32) AFTER accountancy_code_sell; ALTER TABLE llx_product ADD COLUMN accountancy_code_sell_intra varchar(32) AFTER accountancy_code_sell;
ALTER TABLE llx_product ADD COLUMN accountancy_code_sell_export varchar(32) AFTER accountancy_code_sell_intra; ALTER TABLE llx_product ADD COLUMN accountancy_code_sell_export varchar(32) AFTER accountancy_code_sell_intra;
ALTER TABLE llx_facture_rec ADD COLUMN modelpdf varchar(255) AFTER note_public;
ALTER TABLE llx_facture_rec ADD COLUMN generate_pdf integer DEFAULT 0 AFTER auto_validate;
-- SPEC : use database type 'double' to store monetary values -- SPEC : use database type 'double' to store monetary values
ALTER TABLE llx_blockedlog MODIFY COLUMN amounts double(24,8); ALTER TABLE llx_blockedlog MODIFY COLUMN amounts double(24,8);
ALTER TABLE llx_chargessociales MODIFY COLUMN amount double(24,8); ALTER TABLE llx_chargessociales MODIFY COLUMN amount double(24,8);

View File

@ -54,6 +54,7 @@ create table llx_facture_rec
fk_account integer, -- bank account id fk_account integer, -- bank account id
note_private text, note_private text,
note_public text, note_public text,
modelpdf varchar(255),
fk_multicurrency integer, fk_multicurrency integer,
multicurrency_code varchar(255), multicurrency_code varchar(255),
@ -70,5 +71,6 @@ create table llx_facture_rec
date_last_gen datetime DEFAULT NULL, -- date for last gen (date with last successfull generation of invoice) 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_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 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 auto_validate integer DEFAULT 0, -- 0 to create in draft, 1 to create and validate the new invoice
generate_pdf integer DEFAULT 0 -- 0 disable pdf, 1 to generate pdf
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -512,3 +512,5 @@ DeleteRepeatableInvoice=Delete template invoice
ConfirmDeleteRepeatableInvoice=Are your sure you want to delete the template invoice? ConfirmDeleteRepeatableInvoice=Are your sure you want to delete the template invoice?
CreateOneBillByThird=Create one invoice per third party (otherwise, one invoice per order) CreateOneBillByThird=Create one invoice per third party (otherwise, one invoice per order)
BillCreated=%s bill(s) created BillCreated=%s bill(s) created
StatusOfGeneratedDocuments=Status of document generation
AutogenerateDoc=Auto generate document

View File

@ -155,6 +155,7 @@ ErrorPriceExpression19=Expression not found
ErrorPriceExpression20=Empty expression ErrorPriceExpression20=Empty expression
ErrorPriceExpression21=Empty result '%s' ErrorPriceExpression21=Empty result '%s'
ErrorPriceExpression22=Negative result '%s' ErrorPriceExpression22=Negative result '%s'
ErrorPriceExpression23=Unknown or non set variable '%s' in %s
ErrorPriceExpressionInternal=Internal error '%s' ErrorPriceExpressionInternal=Internal error '%s'
ErrorPriceExpressionUnknown=Unknown error '%s' ErrorPriceExpressionUnknown=Unknown error '%s'
ErrorSrcAndTargetWarehouseMustDiffers=Source and target warehouses must differs ErrorSrcAndTargetWarehouseMustDiffers=Source and target warehouses must differs

View File

@ -74,7 +74,7 @@ class PriceExpression
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -121,11 +121,18 @@ class PriceExpression
*/ */
function fetch($id) function fetch($id)
{ {
// Check parameters
if (empty($id))
{
$this->error='ErrorWrongParameters';
return -1;
}
$sql = "SELECT title, expression"; $sql = "SELECT title, expression";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."::fetch"); dol_syslog(__METHOD__);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -160,7 +167,7 @@ class PriceExpression
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " ORDER BY title"; $sql.= " ORDER BY title";
dol_syslog(get_class($this)."::list_price_expression"); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -198,7 +205,7 @@ class PriceExpression
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE title = '".$this->db->escape($title)."'"; $sql.= " WHERE title = '".$this->db->escape($title)."'";
dol_syslog(get_class($this)."::find_title"); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -243,7 +250,7 @@ class PriceExpression
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::update"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -266,7 +273,7 @@ class PriceExpression
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();
@ -314,7 +321,7 @@ class PriceExpression
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE rowid = ".$rowid; $sql.= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::delete"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
} }
@ -324,7 +331,7 @@ class PriceExpression
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();

View File

@ -74,7 +74,7 @@ class PriceGlobalVariable
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(__METHOD__);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -125,7 +125,7 @@ class PriceGlobalVariable
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."::fetch"); dol_syslog(__METHOD__);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -173,7 +173,7 @@ class PriceGlobalVariable
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::update"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -196,7 +196,7 @@ class PriceGlobalVariable
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();
@ -243,7 +243,7 @@ class PriceGlobalVariable
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE rowid = ".$rowid; $sql.= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::delete"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
} }
@ -253,7 +253,7 @@ class PriceGlobalVariable
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();
@ -306,7 +306,7 @@ class PriceGlobalVariable
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " ORDER BY code"; $sql.= " ORDER BY code";
dol_syslog(get_class($this)."::listGlobalVariables"); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {

View File

@ -84,7 +84,7 @@ class PriceGlobalVariableUpdater
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -135,7 +135,7 @@ class PriceGlobalVariableUpdater
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."::fetch"); dol_syslog(__METHOD__);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -191,7 +191,7 @@ class PriceGlobalVariableUpdater
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::update"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -260,7 +260,7 @@ class PriceGlobalVariableUpdater
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE rowid = ".$rowid; $sql.= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::delete"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
} }
@ -270,7 +270,7 @@ class PriceGlobalVariableUpdater
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();
@ -346,7 +346,7 @@ class PriceGlobalVariableUpdater
$sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
dol_syslog(get_class($this)."::listUpdaters"); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -388,7 +388,7 @@ class PriceGlobalVariableUpdater
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE next_update < ".dol_now(); $sql.= " WHERE next_update < ".dol_now();
dol_syslog(get_class($this)."::processUpdaters"); dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -428,6 +428,7 @@ class PriceGlobalVariableUpdater
{ {
global $langs, $user; global $langs, $user;
$langs->load("errors"); $langs->load("errors");
dol_syslog(__METHOD__, LOG_DEBUG);
$this->error = null; $this->error = null;
$this->checkParameters(); $this->checkParameters();
@ -551,7 +552,7 @@ class PriceGlobalVariableUpdater
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::update_next_update"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -560,7 +561,7 @@ class PriceGlobalVariableUpdater
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::update_next_update ".$errmsg, LOG_ERR); dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();
@ -595,7 +596,7 @@ class PriceGlobalVariableUpdater
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::update_status"); dol_syslog(__METHOD__);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
@ -604,7 +605,7 @@ class PriceGlobalVariableUpdater
{ {
foreach($this->errors as $errmsg) foreach($this->errors as $errmsg)
{ {
dol_syslog(get_class($this)."::update_status ".$errmsg, LOG_ERR); dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg); $this->error.=($this->error?', '.$errmsg:$errmsg);
} }
$this->db->rollback(); $this->db->rollback();

View File

@ -85,6 +85,7 @@ class PriceParser
-2 Args -2 Args
6, wrong number of arguments (%s given, %s expected) 6, wrong number of arguments (%s given, %s expected)
23, unknown or non set variable '%s' after %s
-internal errors -internal errors
7, internal error 7, internal error
@ -178,19 +179,34 @@ class PriceParser
$values["global_".$entry->code] = $entry->value; $values["global_".$entry->code] = $entry->value;
} }
//Remove internal variables
unset($values["supplier_id"]);
//Prepare the lib, parameters and values //Prepare the lib, parameters and values
$em = new EvalMath(); $em = new EvalMath();
$em->suppress_errors = true; //Don't print errors on page $em->suppress_errors = true; //Don't print errors on page
$this->error_expr = null; $this->error_expr = null;
$last_result = null; $last_result = null;
//Iterate over each expression splitted by $separator_chr //Fill each variable in expression from values
$expression = str_replace("\n", $this->separator_chr, $expression); $expression = str_replace("\n", $this->separator_chr, $expression);
foreach ($values as $key => $value) foreach ($values as $key => $value)
{ {
if ($value === null) $value = "NULL"; if ($value === null) $value = "NULL";
$expression = str_replace($this->special_chr.$key.$this->special_chr, strval($value), $expression); $expression = str_replace($this->special_chr.$key.$this->special_chr, strval($value), $expression);
} }
//Check if there is unfilled variable
if (strpos($expression, $this->special_chr) !== false)
{
$data = explode($this->special_chr, $expression);
$variable = $this->special_chr.$data[1];
if (isset($data[2])) $variable.= $this->special_chr;
$this->error_parser = array(23, array($variable, $expression));
return -6;
}
//Iterate over each expression splitted by $separator_chr
$expressions = explode($this->separator_chr, $expression); $expressions = explode($this->separator_chr, $expression);
$expressions = array_slice($expressions, 0, $this->limit); $expressions = array_slice($expressions, 0, $this->limit);
foreach ($expressions as $expr) { foreach ($expressions as $expr) {
@ -241,7 +257,7 @@ class PriceParser
//Get the supplier min //Get the supplier min
$productFournisseur = new ProductFournisseur($this->db); $productFournisseur = new ProductFournisseur($this->db);
$supplier_min_price = $productFournisseur->find_min_price_product_fournisseur($product->id); $supplier_min_price = $productFournisseur->find_min_price_product_fournisseur($product->id, 0, 0);
//Accessible values by expressions //Accessible values by expressions
$extra_values = array_merge($extra_values, array( $extra_values = array_merge($extra_values, array(