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

develop

Conflicts:
	htdocs/core/class/commonobject.class.php
This commit is contained in:
Florian HENRY 2016-04-27 09:41:42 +02:00
commit 1d75c5f720
7 changed files with 136 additions and 95 deletions

View File

@ -341,6 +341,17 @@ class FactureRec extends CommonInvoice
}
/**
* Create an array of invoice lines
*
* @return int >0 if OK, <0 if KO
*/
function getLinesArray()
{
return $this->fetch_lines();
}
/**
* Recupere les lignes de factures predefinies dans this->lines
*
@ -348,16 +359,23 @@ class FactureRec extends CommonInvoice
*/
function fetch_lines()
{
$this->lines=array();
$sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.tva_tx, ';
$sql.= ' l.remise, l.remise_percent, l.subprice,';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc,';
$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
//$sql.= ' l.situation_percent, l.fk_prev_id,';
//$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice,';
$sql.= ' l.rang, l.special_code,';
//$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
$sql.= ' l.fk_unit, l.fk_contract_line,';
//$sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
$sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
$sql.= ' WHERE l.fk_facture = '.$this->id;
$sql.= ' ORDER BY l.rang';
dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
@ -387,10 +405,6 @@ class FactureRec extends CommonInvoice
$line->remise_percent = $objp->remise_percent;
$line->fk_remise_except = $objp->fk_remise_except;
$line->fk_product = $objp->fk_product;
$line->date_start = $objp->date_start;
$line->date_end = $objp->date_end;
$line->date_start = $objp->date_start;
$line->date_end = $objp->date_end;
$line->info_bits = $objp->info_bits;
$line->total_ht = $objp->total_ht;
$line->total_tva = $objp->total_tva;
@ -415,7 +429,7 @@ class FactureRec extends CommonInvoice
}
else
{
$this->error=$this->db->error();
$this->error=$this->db-lasterror();
return -3;
}
}

View File

@ -73,6 +73,13 @@ if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
}
}
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('invoicecard','globalcard'));
$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
/*
* Actions
@ -101,7 +108,7 @@ if ($action == 'add')
$rehour=GETPOST('rehour');
$remin=GETPOST('remin');
$nb_gen_max=GETPOST('nb_gen_max', 'int');
if (empty($nb_gen_max)) $nb_gen_max =0;
//if (empty($nb_gen_max)) $nb_gen_max =0;
if (GETPOST('frequency'))
{
@ -111,7 +118,7 @@ if ($action == 'add')
$action = "create";
$error++;
}
if ($nb_gen_max == '')
if ($nb_gen_max === '')
{
setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("MaxPeriodNumber")), null, 'errors');
$action = "create";
@ -599,7 +606,9 @@ if ($action == 'create')
if ($object->fetch($id, $ref) > 0)
{
print '<form action="fiche-rec.php" method="post">';
$result = $object->getLinesArray();
print '<form action="fiche-rec.php" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="facid" value="'.$object->id.'">';
@ -707,10 +716,22 @@ if ($action == 'create')
print load_fiche_titre($title, '', '');
/*
* Invoice lines
*/
print '<table id="tablelines" class="noborder noshadow" width="100%">';
// Show object lines
if (! empty($object->lines))
{
$disableedit=1;
$disablemove=1;
$disableremove=1;
$ret = $object->printObjectLines('', $mysoc, $soc, $lineid, 0); // No date selector for template invoice
}
print "</table>\n";
/*
print '<table class="notopnoleftnoright" width="100%">';
print '<tr><td colspan="3">';
@ -877,7 +898,8 @@ if ($action == 'create')
print $db->error();
}
print "</table>";
*/
print '</td></tr>';
if ($flag_price_may_change)

View File

@ -3236,7 +3236,9 @@ abstract class CommonObject
*/
function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0)
{
global $conf, $hookmanager, $inputalsopricewithtax, $usemargins, $langs, $user;
global $conf, $hookmanager, $langs, $user;
// TODO We should not use global var for this !
global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove;
// Define usemargins
$usemargins=0;

View File

@ -31,7 +31,7 @@
* $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
* $usemargins (0 to disable all margins columns, 1 to show according to margin setup)
* $object_rights->creer initialized from = $object->getRights()
* $disableedit, $disablemove
* $disableedit, $disablemove, $disableremove
*
* $type, $text, $description, $line
*/
@ -46,7 +46,6 @@ if (empty($forceall)) $forceall=0;
if (empty($senderissupplier)) $senderissupplier=0;
if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
if (empty($usemargins)) $usemargins=0;
?>
<?php $coldisplay=0; ?>
<!-- BEGIN PHP TEMPLATE objectline_view.tpl.php -->
@ -216,7 +215,7 @@ if (empty($usemargins)) $usemargins=0;
<td class="linecoldelete" align="center"><?php $coldisplay++; ?>
<?php
if ($this->situation_counter == 1 || !$this->situation_cycle_ref) {
if (($this->situation_counter == 1 || !$this->situation_cycle_ref) && empty($disableremove)) {
print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $this->id . '&amp;action=ask_deleteline&amp;lineid=' . $line->id . '">';
print img_delete();
print '</a>';

View File

@ -664,7 +664,7 @@ class Expedition extends CommonObject
$langs->load("agenda");
// Loop on each product line to add a stock movement
// TODO possibilite d'expedier a partir d'une propale ou autre origine
// TODO in future, shipment lines may not be linked to order line
$sql = "SELECT cd.fk_product, cd.subprice,";
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
@ -738,7 +738,7 @@ class Expedition extends CommonObject
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('SHIPPING_VALIDATE',$user);
$result=$this->call_trigger('SHIPPING_VALIDATE',$user); // TODO Add option in workflow module on this trigger to close order if sum of shipment = product to ship of order
if ($result < 0) { $error++; }
// End call triggers
}

View File

@ -47,7 +47,7 @@ class WebsitePage extends CommonObject
/**
*/
public $fk_website;
public $pageurl;
public $title;
@ -61,7 +61,7 @@ class WebsitePage extends CommonObject
/**
*/
/**
* Constructor
@ -87,7 +87,7 @@ class WebsitePage extends CommonObject
$error = 0;
$now=dol_now();
// Clean parameters
if (isset($this->fk_website)) {
$this->fk_website = trim($this->fk_website);
@ -167,7 +167,7 @@ class WebsitePage extends CommonObject
}
// Commit or rollback
if ($error)
if ($error)
{
$this->db->rollback();
@ -194,7 +194,7 @@ class WebsitePage extends CommonObject
$sql = 'SELECT';
$sql .= ' t.rowid,';
$sql .= " t.fk_website,";
$sql .= " t.pageurl,";
$sql .= " t.title,";
@ -205,7 +205,7 @@ class WebsitePage extends CommonObject
$sql .= " t.date_creation,";
$sql .= " t.date_modification,";
$sql .= " t.tms";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if (null !== $website_id) {
$sql .= ' WHERE t.fk_website = ' . '\'' . $website_id . '\'';
@ -221,7 +221,7 @@ class WebsitePage extends CommonObject
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->fk_website = $obj->fk_website;
$this->pageurl = $obj->pageurl;
$this->title = $obj->title;
@ -233,7 +233,7 @@ class WebsitePage extends CommonObject
$this->date_modification = $this->db->jdate($obj->date_modification);
$this->tms = $this->db->jdate($obj->tms);
}
$this->db->free($resql);
@ -251,23 +251,24 @@ class WebsitePage extends CommonObject
}
/**
*
* Load object in memory from the database
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit limit
* @param int $offset Offset
* @param array $filter Filter array
* @param string $filtermode Filter mode (AND or OR)
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param number $limit limit
* @param number $offset Offset
* @param array $filter Filter array
* @param string $filtermode Filter mode (AND or OR)
*
* @return array|int int <0 if KO, array of pages if OK
*/
public function fetchAll($website_id, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
$records=array();
$sql = 'SELECT';
$sql .= ' t.rowid,';
$sql .= " t.fk_website,";
@ -281,18 +282,21 @@ class WebsitePage extends CommonObject
$sql .= " t.date_modification,";
$sql .= " t.tms";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' WHERE t.fk_website = '.$website_id;
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
if ($key=='t.rowid' || $key=='t.fk_website') {
$sqlwhere [] = $key . '='. $value;
} else {
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere);
}
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield,$sortorder);
}
@ -305,7 +309,7 @@ class WebsitePage extends CommonObject
if ($resql) {
$num = $this->db->num_rows($resql);
while ($obj = $this->db->fetch_object($resql))
while ($obj = $this->db->fetch_object($resql))
{
$record = new Websitepage($this->db);
@ -349,7 +353,7 @@ class WebsitePage extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
// Clean parameters
if (isset($this->fk_website)) {
$this->fk_website = trim($this->fk_website);
}
@ -372,14 +376,14 @@ class WebsitePage extends CommonObject
$this->status = trim($this->status);
}
// Check parameters
// Put here code to add a control on parameters values
// Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
$sql .= ' fk_website = '.(isset($this->fk_website)?$this->fk_website:"null").',';
$sql .= ' pageurl = '.(isset($this->pageurl)?"'".$this->db->escape($this->pageurl)."'":"null").',';
$sql .= ' title = '.(isset($this->title)?"'".$this->db->escape($this->title)."'":"null").',';
@ -391,7 +395,7 @@ class WebsitePage extends CommonObject
$sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').',';
$sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'");
$sql .= ' WHERE rowid=' . $this->id;
$this->db->begin();
@ -561,7 +565,7 @@ class WebsitePage extends CommonObject
$result.= $link . $this->ref . $linkend;
return $result;
}
/**
* Retourne le libelle du status d'un user (actif, inactif)
*
@ -616,8 +620,8 @@ class WebsitePage extends CommonObject
if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
}
}
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
@ -627,7 +631,7 @@ class WebsitePage extends CommonObject
public function initAsSpecimen()
{
$this->id = 0;
$this->fk_website = '';
$this->pageurl = '';
$this->title = '';
@ -639,7 +643,7 @@ class WebsitePage extends CommonObject
$this->date_modification = '';
$this->tms = '';
}
}

View File

@ -109,20 +109,20 @@ if ($pageid)
if ($action == 'add')
{
$db->begin();
$objectpage->fk_website = $object->id;
$objectpage->title = GETPOST('WEBSITE_TITLE');
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
$objectpage->keyword = GETPOST('WEBSITE_KEYWORD');
if (empty($objectpage->title))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
$error++;
}
if (! $error)
{
$res = $objectpage->create($user);
@ -148,27 +148,27 @@ if ($action == 'add')
if ($action == 'update')
{
$db->begin();
$res = $object->fetch(0, $website);
$objectpage->fk_website = $object->id;
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
$res = $objectpage->fetch(0, $object->fk_website, $objectpage->pageurl);
if ($res > 0)
{
$objectpage->title = GETPOST('WEBSITE_TITLE');
$objectpage->description = GETPOST('WEBSITE_DESCRIPTION');
$objectpage->keyword = GETPOST('WEBSITE_KEYWORD');
$res = $objectpage->update($user);
if (! $res > 0)
{
$error++;
setEventMessages($objectpage->error, $objectpage->errors, 'errors');
}
if (! $error)
{
$db->commit();
@ -190,25 +190,25 @@ if ($action == 'update')
if ($action == 'updatecontent')
{
$db->begin();
$object->fetch(0, $website);
$objectpage->fk_website = $object->id;
$objectpage->pageurl = GETPOST('WEBSITE_PAGENAME');
$res = $objectpage->fetch(0, $object->fk_website, $objectpage->pageurl);
if ($res > 0)
{
$objectpage->content = GETPOST('PAGE_CONTENT');
$res = $objectpage->update($user);
if (! $res > 0)
{
$error++;
setEventMessages($objectpage->error, $objectpage->errors, 'errors');
}
if (! $error)
{
$db->commit();
@ -268,7 +268,7 @@ if (count($object->records) > 0)
print '<div class="websiteselection">';
print $langs->trans("Website").': ';
print '</div>';
print '<div class="websiteselection">';
// Loop on each sites
$i=0;
@ -282,15 +282,15 @@ if (count($object->records) > 0)
print $valwebsite->ref;
if ($valwebsite->ref == $website) print '</strong>';
print '</a>';
$i++;
$i++;
}
print '</div>';
print '<div class="websitetools">';
if ($action == 'preview')
if ($action == 'preview')
{
$disabled='';
if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"';
@ -299,17 +299,17 @@ if (count($object->records) > 0)
print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("AddPage")).'" name="create">';
}
//else print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
print '</div>';
// Part for pages
if ($website)
{
print '</div>';
$array=$objectpage->fetchAll($object->id);
$array=$objectpage->fetchAll('','',0,0,array('t.fk_website'=>$object->id));
print '<div class="centpercent websitebar"'.($style?' style="'.$style.'"':'').'">';
print '<div class="websiteselection">';
print $langs->trans("Page").': ';
@ -320,7 +320,7 @@ if (count($object->records) > 0)
foreach($array as $key => $valpage)
{
if (empty($pageid) && $action != 'create') $pageid=$valpage->id;
$out.='<option value="'.$key.'"';
if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value
$out.='>';
@ -334,14 +334,14 @@ if (count($object->records) > 0)
print '</div>';
print '<div class="websiteselection">';
print '</div>';
print '<div class="websitetools">';
if ($action == 'preview')
{
$disabled='';
if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"';
if ($pageid > 0)
{
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
@ -351,10 +351,10 @@ if (count($object->records) > 0)
else print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
if (preg_match('/^create/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action)) print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
print '</div>';
}
}
}
else
{
@ -378,17 +378,17 @@ $head = array();
if ($action == 'editmeta' || $action == 'create')
{
print '<div class="fiche">';
dol_fiche_head();
print '<table class="border" width="100%">';
print '<tr><td>';
print $langs->trans('WEBSITE_PAGENAME');
print '</td><td>';
print '<input type="text" class="flat" size="96" name="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($page).'">';
print '</td></tr>';
if ($action != 'create')
{
print '<tr><td>';
@ -397,31 +397,31 @@ if ($action == 'editmeta' || $action == 'create')
print '/public/websites/'.$website.'/index.php?pageid='.urlencode($pageid);
print '</td></tr>';
}
print '<tr><td>';
print $langs->trans('WEBSITE_TITLE');
print '</td><td>';
print '<input type="text" class="flat" size="96" name="WEBSITE_TITLE" value="'.dol_escape_htmltag($obj->WEBSITE_TITLE).'">';
print '</td></tr>';
print '<tr><td>';
print $langs->trans('WEBSITE_DESCRIPTION');
print '</td><td>';
print '<input type="text" class="flat" size="96" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($obj->WEBSITE_DESCRIPTION).'">';
print '</td></tr>';
print '<tr><td>';
print $langs->trans('WEBSITE_KEYWORDS');
print '</td><td>';
print '<input type="text" class="flat" size="128" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($obj->WEBSITE_KEYWORDS).'">';
print '</td></tr>';
print '</table>';
dol_fiche_end();
print '</div>';
print '<br>';
}
@ -449,7 +449,7 @@ if ($action == 'preview')
if ($pageid > 0)
{
$objectpage->fetch($pageid);
print '<!-- Page content -->'."\n";
print '<div class="websitecontent">';
print $objectpage->content;
@ -462,7 +462,7 @@ if ($action == 'preview')
}
}
llxFooter();