diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 0acd58f0202..b18c5bf7b48 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -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; } } diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index ad9626718c6..2e595d45daf 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -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 '
'; + $result = $object->getLinesArray(); + + print ''; print ''; print ''; print ''; @@ -707,10 +716,22 @@ if ($action == 'create') print load_fiche_titre($title, '', ''); - /* * Invoice lines */ + print ''; + // 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 "
\n"; + + /* print ''; print '
'; @@ -877,7 +898,8 @@ if ($action == 'create') print $db->error(); } print "
"; - + */ + print ''; if ($flag_price_may_change) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6ec3ef6fdba..d296e9a26ed 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -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; diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 967d9f81970..559cae91464 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -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; - ?> @@ -216,7 +215,7 @@ if (empty($usemargins)) $usemargins=0; situation_counter == 1 || !$this->situation_cycle_ref) { + if (($this->situation_counter == 1 || !$this->situation_cycle_ref) && empty($disableremove)) { print 'id . '">'; print img_delete(); print ''; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 0024c1a9375..6ddf05401da 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -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 } diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index ac9adf8f480..ef1cd176760 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -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 = ''; - + } } diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 58a2981d2da..a6f3ddebd87 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -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 '
'; print $langs->trans("Website").': '; print '
'; - + print '
'; // Loop on each sites $i=0; @@ -282,15 +282,15 @@ if (count($object->records) > 0) print $valwebsite->ref; if ($valwebsite->ref == $website) print ''; print ''; - - $i++; + + $i++; } - + print '
'; - + print '
'; - - 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 ''; } //else print ''; - + print '
'; - - + + // Part for pages if ($website) { print ''; - $array=$objectpage->fetchAll($object->id); - + $array=$objectpage->fetchAll('','',0,0,array('t.fk_website'=>$object->id)); + print '
'; print '
'; 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.='
'; print '
'; print '
'; - + print '
'; - + if ($action == 'preview') { $disabled=''; if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"'; - + if ($pageid > 0) { print ''; @@ -351,10 +351,10 @@ if (count($object->records) > 0) else print ''; if (preg_match('/^create/',$action)) print ''; if (preg_match('/^edit/',$action)) print ''; - + print '
'; - - } + + } } else { @@ -378,17 +378,17 @@ $head = array(); if ($action == 'editmeta' || $action == 'create') { print '
'; - + dol_fiche_head(); - + print ''; - + print ''; - + if ($action != 'create') { print ''; } - + print ''; - + print ''; - + print ''; - + print '
'; print $langs->trans('WEBSITE_PAGENAME'); print ''; print ''; print '
'; @@ -397,31 +397,31 @@ if ($action == 'editmeta' || $action == 'create') print '/public/websites/'.$website.'/index.php?pageid='.urlencode($pageid); print '
'; print $langs->trans('WEBSITE_TITLE'); print ''; print ''; print '
'; print $langs->trans('WEBSITE_DESCRIPTION'); print ''; print ''; print '
'; print $langs->trans('WEBSITE_KEYWORDS'); print ''; print ''; print '
'; - + dol_fiche_end(); - + print '
'; - + print '
'; } @@ -449,7 +449,7 @@ if ($action == 'preview') if ($pageid > 0) { $objectpage->fetch($pageid); - + print ''."\n"; print '
'; print $objectpage->content; @@ -462,7 +462,7 @@ if ($action == 'preview') } } - + llxFooter();