diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 0f2dfb5e52b..885fb4b26a3 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -40,6 +40,7 @@ $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'bomcard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); +$lineid = GETPOST('lineid', 'int'); // Initialize technical objects $object=new BOM($db); @@ -141,6 +142,7 @@ if (empty($reshook)) if ($result <= 0) { setEventMessages($bomline->error, $bomline->errors, 'errors'); + $action = ''; } } } @@ -148,14 +150,12 @@ if (empty($reshook)) /* * View - * - * Put here all code to build page */ $form=new Form($db); $formfile=new FormFile($db); -llxHeader('', 'NewBOM', ''); +llxHeader('', $langs->trans("BOM"), ''); // Example : Adding jquery code print ''; + print ''; +} + +print "\n"; +print "\n"; +?> + + \ No newline at end of file diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 46c25e3674c..d3fb1f7607b 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -24,11 +24,9 @@ * $object (invoice, order, ...) * $conf * $langs - * $dateSelector * $forceall (0 by default, 1 for supplier invoices/orders) * $element (used to test $user->rights->$element->creer) * $permtoedit (used to replace test $user->rights->$element->creer) - * $senderissupplier (0 by default, 1 for supplier invoices/orders) * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) * $object_rights->creer initialized from = $object->getRights() * $disableedit, $disablemove, $disableremove @@ -58,6 +56,8 @@ $domData .= ' data-id="'.$line->id.'"'; $domData .= ' data-qty="'.$line->qty.'"'; $domData .= ' data-product_type="'.$line->product_type.'"'; +// Lines for extrafield +$objectline = new BOMLine($this->db); ?> @@ -68,146 +68,17 @@ $domData .= ' data-product_type="'.$line->product_type.'"';
info_bits & 2) == 2) { - ?> - - trans("ShowReduc"), 'reduc').' '; - if ($line->description == '(DEPOSIT)') $txt=$langs->trans("Deposit"); - elseif ($line->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); - elseif ($line->description == '(EXCESS PAID)') $txt=$langs->trans("ExcessPaid"); - //else $txt=$langs->trans("Discount"); - print $txt; - ?> - - description) - { - if ($line->description == '(CREDIT_NOTE)' && $line->fk_remise_except > 0) - { - $discount=new DiscountAbsolute($this->db); - $discount->fetch($line->fk_remise_except); - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); - } - elseif ($line->description == '(DEPOSIT)' && $line->fk_remise_except > 0) - { - $discount=new DiscountAbsolute($this->db); - $discount->fetch($line->fk_remise_except); - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); - // Add date of deposit - if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) - echo ' ('.dol_print_date($discount->datec).')'; - } - elseif ($line->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) - { - $discount=new DiscountAbsolute($this->db); - $discount->fetch($line->fk_remise_except); - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0)); - } - elseif ($line->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) - { - $discount=new DiscountAbsolute($this->db); - $discount->fetch($line->fk_remise_except); - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0)); - } - else - { - echo ($txt?' - ':'').dol_htmlentitiesbr($line->description); - } - } - } - else - { - $format = $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE?'dayhour':'day'; - - if ($line->fk_product > 0) - { - echo $form->textwithtooltip($text, $description, 3, '', '', $i, 0, (!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):'')); - } - else - { - if ($type==1) $text = img_object($langs->trans('Service'), 'service'); - else $text = img_object($langs->trans('Product'), 'product'); - - if (! empty($line->label)) { - $text.= ' '.$line->label.''; - echo $form->textwithtooltip($text, dol_htmlentitiesbr($line->description), 3, '', '', $i, 0, (!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):'')); - } else { - if (! empty($line->fk_parent_line)) echo img_picto('', 'rightarrow'); - echo $text.' '.dol_htmlentitiesbr($line->description); - } - } - - // Show date range - if ($line->element == 'facturedetrec') { - if ($line->date_start_fill || $line->date_end_fill) echo '
'; - if ($line->date_start_fill) echo $langs->trans('AutoFillDateFromShort').': '.yn($line->date_start_fill); - if ($line->date_start_fill && $line->date_end_fill) echo ' - '; - if ($line->date_end_fill) echo $langs->trans('AutoFillDateToShort').': '.yn($line->date_end_fill); - if ($line->date_start_fill || $line->date_end_fill) echo '
'; - } - else { - if ($line->date_start || $line->date_end) echo '
'.get_date_range($line->date_start, $line->date_end, $format).'
'; - //echo get_date_range($line->date_start, $line->date_end, $format); - } - + echo $form->textwithtooltip($text, $description, 3, '', '', $i, 0, (!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):'')); // Add description in form - if ($line->fk_product > 0 && ! empty($conf->global->PRODUIT_DESC_IN_FORM)) + if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) { print (! empty($line->description) && $line->description!=$line->product_label)?'
'.dol_htmlentitiesbr($line->description):''; } - } - - if (! empty($conf->accounting->enabled) && $line->fk_accounting_account > 0) - { - $accountingaccount=new AccountingAccount($this->db); - $accountingaccount->fetch($line->fk_accounting_account); - echo '

' . $langs->trans('AccountingAffectation') . ' : ' . $accountingaccount->getNomUrl(0, 1, 1); - } - ?> - element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines - { - ?> - ref_fourn?$line->ref_fourn:$line->ref_supplier); - ?> - - tva_tx)) $positiverates.=($positiverates?'/':'').price2num($line->tva_tx); - if (price2num($line->total_localtax1)) $positiverates.=($positiverates?'/':'').price2num($line->localtax1_tx); - if (price2num($line->total_localtax2)) $positiverates.=($positiverates?'/':'').price2num($line->localtax2_tx); - if (empty($positiverates)) $positiverates='0'; - echo vatrate($positiverates.($line->vat_src_code?' ('.$line->vat_src_code.')':''), '%', $line->info_bits); - //echo vatrate($line->tva_tx.($line->vat_src_code?(' ('.$line->vat_src_code.')'):''), '%', $line->info_bits); - ?> - - subprice); ?> - - multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { ?> - multicurrency_subprice); ?> - - - - pu_ttc)?price($line->pu_ttc):price($line->subprice)); ?> - - info_bits & 2) != 2) && $line->special_code != 3) { - // I comment this because it shows info even when not required - // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated - // must also not be output for most entities (proposal, intervention, ...) - //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." "; - echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price - } else echo ' '; + echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price ?> @@ -222,54 +93,14 @@ $domData .= ' data-product_type="'.$line->product_type.'"'; print ''; } ?> - - remise_percent) && $line->special_code != 3) { ?> - remise_percent, $langs); - ?> - -   - global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); - - ?> - - special_code == 3) { ?> - trans('Option'); ?> - - global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - print 'country_code).'='.price($line->total_ht); - print '
'.$langs->transcountry("TotalVAT", ($senderissupplier?$object->thirdparty->country_code:$mysoc->country_code)).'='.price($line->total_tva); - if (price2num($line->total_localtax1)) print '
'.$langs->transcountry("TotalLT1", ($senderissupplier?$object->thirdparty->country_code:$mysoc->country_code)).'='.price($line->total_localtax1); - if (price2num($line->total_localtax2)) print '
'.$langs->transcountry("TotalLT2", ($senderissupplier?$object->thirdparty->country_code:$mysoc->country_code)).'='.price($line->total_localtax2); - print '
'.$langs->transcountry("TotalTTC", $mysoc->country_code).'='.price($line->total_ttc); - print '">'; - } - print price($line->total_ht); - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - print '
'; - } - ?> - - multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { ?> - multicurrency_total_ht); ?> - - - - total_ttc); ?> - - - + + efficiency; + ?> + statut == 0 && ($object_rights->creer) && $action != 'selectlines' ) { ?> + + if ($this->statut == 0 && ($object_rights->write) && $action != 'selectlines' ) { ?> info_bits & 2) == 2 || ! empty($disableedit)) { ?> @@ -282,7 +113,7 @@ $domData .= ' data-product_type="'.$line->product_type.'"'; fk_prev_id == null ) && empty($disableremove)) { //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation - print 'id . '">'; + print 'id . '">'; print img_delete(); print ''; } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index d21b383bf97..0ac28e92bb0 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1752,7 +1752,6 @@ class Contrat extends CommonObject if ($this->statut >= 0) { - // Call trigger $result=$this->call_trigger('LINECONTRACT_DELETE', $user); if ($result < 0) return -1; @@ -1760,10 +1759,10 @@ class Contrat extends CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element_line; $sql.= " WHERE rowid=".$idline; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); + dol_syslog(get_class($this)."::deleteline", LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { @@ -1781,7 +1780,7 @@ class Contrat extends CommonObject if ($result < 0) { $error++; - $this->error="Error ".get_class($this)."::delete deleteExtraFields error -4 ".$contractline->error; + $this->error="Error ".get_class($this)."::deleteline deleteExtraFields error -4 ".$contractline->error; } } } @@ -1790,7 +1789,7 @@ class Contrat extends CommonObject $this->db->commit(); return 1; } else { - dol_syslog(get_class($this)."::delete ERROR:".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::deleteline ERROR:".$this->error, LOG_ERR); $this->db->rollback(); return -1; } diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 3bd33c94c15..40529413bbe 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -195,8 +195,45 @@ if ($action == 'confirm_delete' && ! empty($permissiontodelete)) } } +// Remove a line +if ($action == 'confirm_deleteline' && $confirm == 'yes' && ! empty($permissiontoadd)) +{ + $result = $object->deleteline($user, $lineid); + if ($result > 0) + { + // Define output language + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) + { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($object->thirdparty)) + { + $newlang = $object->thirdparty->default_lang; + } + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $ret = $object->fetch($object->id); // Reload to get new records + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + + setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + + // Action clone object -if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) +if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd)) { if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) { diff --git a/htdocs/core/actions_fetchobject.inc.php b/htdocs/core/actions_fetchobject.inc.php index 780895e47a9..dc8ee938bfc 100644 --- a/htdocs/core/actions_fetchobject.inc.php +++ b/htdocs/core/actions_fetchobject.inc.php @@ -32,8 +32,8 @@ if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtas { if (($id > 0 && is_numeric($id)) || ! empty($ref)) // To discard case when id is list of ids like '1,2,3...' { - $ret = $object->fetch($id, $ref); - if ($ret > 0) + $ret = $object->fetch($id, $ref); + if ($ret > 0) { $object->fetch_thirdparty(); $id = $object->id; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a064e611c2f..9852e2f2fb0 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3911,12 +3911,13 @@ abstract class CommonObject * @param string $buyer Object of buyer third party * @param int $selected Object line selected * @param int $dateSelector 1=Show also date range input fields + * @param string $defaulttpldir Directory where to find the template * @return void */ - public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0) + public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir = '/core/tpl') { - global $conf, $hookmanager, $langs, $user; - // TODO We should not use global var for this ! + global $conf, $hookmanager, $langs, $user, $object, $form; + // TODO We should not use global var for this global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; // Define usemargins @@ -3934,90 +3935,26 @@ abstract class CommonObject $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { - // Title line - print "\n"; - - print ''; - - // Adds a line numbering column - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print ' '; - - // Description - print ''.$langs->trans('Description').''; - - if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') + // Output template part (modules that overwrite templates must declare this into descriptor) + // Use global variables + $dateSelector + $seller and $buyer + $dirtpls=array_merge($conf->modules_parts['tpl'], array($defaulttpldir)); + foreach($dirtpls as $module => $reldir) { - print ''.$langs->trans("SupplierRef").''; - } - - // VAT - print ''.$langs->trans('VAT').''; - - // Price HT - print ''.$langs->trans('PriceUHT').''; - - // Multicurrency - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print ''.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).''; - - if ($inputalsopricewithtax) print ''.$langs->trans('PriceUTTC').''; - - // Qty - print ''.$langs->trans('Qty').''; - - if($conf->global->PRODUCT_USE_UNITS) - { - print ''.$langs->trans('Unit').''; - } - - // Reduction short - print ''.$langs->trans('ReductionShort').''; - - // Fields for situation invoice - if ($this->situation_cycle_ref) { - print '' . $langs->trans('Progress') . ''; - print '' . $langs->trans('TotalHT100Short') . ''; - } - - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) - { - if (!empty($user->rights->margins->creer)) + if (!empty($module)) { - if ($conf->global->MARGIN_TYPE == "1") - print ''.$langs->trans('BuyingPrice').''; - else - print ''.$langs->trans('CostPrice').''; + $tpl = dol_buildpath($reldir.'/objectline_title.tpl.php'); } - - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) - print ''.$langs->trans('MarginRate').''; - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) - print ''.$langs->trans('MarkRate').''; + else + { + $tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_title.tpl.php'; + } + if (empty($conf->file->strict_mode)) { + $res=@include $tpl; + } else { + $res=include $tpl; // for debug + } + if ($res) break; } - - // Total HT - print ''.$langs->trans('TotalHTShort').''; - - // Multicurrency - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print ''.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).''; - - if ($outputalsopricetotalwithtax) print ''.$langs->trans('TotalTTCShort').''; - - print ''; // No width to allow autodim - - print ''; - - print ''; - - if($action == 'selectlines') - { - print ''; - print ''; - print ''; - print ''; - } - - print "\n"; - print "\n"; } $var = true; @@ -4045,7 +3982,7 @@ abstract class CommonObject } if (empty($reshook)) { - $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline); + $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline, $defaulttpldir); } $i++; @@ -4067,9 +4004,10 @@ abstract class CommonObject * @param string $buyer Object of buyer third party * @param int $selected Object line selected * @param int $extrafieldsline Object of extrafield line attribute + * @param string $defaulttpldir Directory where to find the template * @return void */ - public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0) + public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0, $defaulttpldir = '/core/tpl') { global $conf,$langs,$user,$object,$hookmanager; global $form,$bc,$bcdd; @@ -4103,7 +4041,7 @@ abstract class CommonObject // Define output language and label if (! empty($conf->global->MAIN_MULTILANGS)) { - if (! is_object($this->thirdparty)) + if (property_exists($this, 'socid') && ! is_object($this->thirdparty)) { dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); return; @@ -4115,7 +4053,7 @@ abstract class CommonObject $outputlangs = $langs; $newlang=''; if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang=GETPOST('lang_id', 'aZ09'); - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer + if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) $newlang=$this->thirdparty->default_lang; // To use language of customer if (! empty($newlang)) { $outputlangs = new Translate("", $conf); @@ -4137,7 +4075,7 @@ abstract class CommonObject // Output template part (modules that overwrite templates must declare this into descriptor) // Use global variables + $dateSelector + $seller and $buyer - $dirtpls=array_merge($conf->modules_parts['tpl'], array('/core/tpl')); + $dirtpls=array_merge($conf->modules_parts['tpl'], array($defaulttpldir)); foreach($dirtpls as $module => $reldir) { if (!empty($module)) @@ -4157,7 +4095,7 @@ abstract class CommonObject } } - // Ligne en mode update + // Line in update mode if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) { $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); @@ -4167,7 +4105,7 @@ abstract class CommonObject // Output template part (modules that overwrite templates must declare this into descriptor) // Use global variables + $dateSelector + $seller and $buyer - $dirtpls=array_merge($conf->modules_parts['tpl'], array('/core/tpl')); + $dirtpls=array_merge($conf->modules_parts['tpl'], array($defaulttpldir)); foreach($dirtpls as $module => $reldir) { if (!empty($module)) @@ -7370,6 +7308,56 @@ abstract class CommonObject } } + /** + * Load object in memory from the database + * + * @param string $morewhere More SQL filters (' AND ...') + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetchLinesCommon($morewhere = '') + { + $objectlineclassname = get_class($this).'Line'; + if (! class_exists($objectlineclassname)) + { + $this->error = 'Error, class '.$objectlineclassname.' not found during call of fetchLinesCommon'; + return -1; + } + + $objectline = new $objectlineclassname($this->db); + + $sql = 'SELECT '.$objectline->getFieldList(); + $sql.= ' FROM '.MAIN_DB_PREFIX.$objectline->table_element; + $sql.=' WHERE fk_'.$this->element.' = '.$this->id; + if ($morewhere) $sql.= $morewhere; + + $resql = $this->db->query($sql); + if ($resql) + { + $num_rows = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_rows) + { + $obj = $this->db->fetch_object($resql); + if ($obj) + { + $newline = new $objectlineclassname($this->db); + $newline->setVarsFromFetchObj($obj); + + $this->lines[] = $newline; + } + $i++; + } + + return 1; + } + else + { + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + return -1; + } + } + /** * Update object into database * @@ -7541,6 +7529,66 @@ abstract class CommonObject } } + /** + * Delete a line of object in database + * + * @param User $user User that delete + * @param int $idline Id of line to delete + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int >0 if OK, <0 if KO + */ + public function deleteLineCommon(User $user, $idline, $notrigger = false) + { + global $conf; + + $error=0; + + $tmpforobjectclass = get_class($this); + $tmpforobjectlineclass = ucfirst($tmpforobjectclass).'Line'; + + // Call trigger + $result=$this->call_trigger('LINE'.strtoupper($tmpforobjectclass).'_DELETE', $user); + if ($result < 0) return -1; + // End call triggers + + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql.= " WHERE rowid=".$idline; + + dol_syslog(get_class($this)."::deleteLineCommon", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error="Error ".$this->db->lasterror(); + $error++; + } + + if (empty($error)) { + // Remove extrafields + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $tmpobjectline = new $tmpforobjectlineclass($this->db); + $tmpobjectline->id= $idline; + $result=$tmpobjectline->deleteExtraFields(); + if ($result < 0) + { + $error++; + $this->error="Error ".get_class($this)."::deleteLineCommon deleteExtraFields error -4 ".$tmpobjectline->error; + } + } + } + + if (empty($error)) { + $this->db->commit(); + return 1; + } else { + dol_syslog(get_class($this)."::deleteLineCommon ERROR:".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + /** * Initialise object with example values * Id must be 0 if object instance is a specimen diff --git a/htdocs/core/tpl/objectline_title.tpl.php b/htdocs/core/tpl/objectline_title.tpl.php new file mode 100644 index 00000000000..fd848764721 --- /dev/null +++ b/htdocs/core/tpl/objectline_title.tpl.php @@ -0,0 +1,131 @@ + + * Copyright (C) 2010-2011 Laurent Destailleur + * Copyright (C) 2012-2013 Christophe Battarel + * Copyright (C) 2012 Cédric Salvador + * Copyright (C) 2012-2014 Raphaël Doursenaud + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2017 Juanjo Menent + * + * 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 . + * + * Need to have following variables defined: + * $object (invoice, order, ...) + * $conf + * $langs + * $element (used to test $user->rights->$element->creer) + * $permtoedit (used to replace test $user->rights->$element->creer) + * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) + * $outputalsopricetotalwithtax + * $usemargins (0 to disable all margins columns, 1 to show according to margin setup) + * + * $type, $text, $description, $line + */ + +// Protection to avoid direct call of template +if (empty($object) || ! is_object($object)) +{ + print "Error, template page can't be called as URL"; + exit; +} +?> + +\n"; + +print ''; + +// Adds a line numbering column +if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print ' '; + +// Description +print ''.$langs->trans('Description').''; + +if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') +{ + print ''.$langs->trans("SupplierRef").''; +} + +// VAT +print ''.$langs->trans('VAT').''; + +// Price HT +print ''.$langs->trans('PriceUHT').''; + +// Multicurrency +if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print ''.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).''; + +if ($inputalsopricewithtax) print ''.$langs->trans('PriceUTTC').''; + +// Qty +print ''.$langs->trans('Qty').''; + +if($conf->global->PRODUCT_USE_UNITS) +{ + print ''.$langs->trans('Unit').''; +} + +// Reduction short +print ''.$langs->trans('ReductionShort').''; + +// Fields for situation invoice +if ($this->situation_cycle_ref) { + print '' . $langs->trans('Progress') . ''; + print '' . $langs->trans('TotalHT100Short') . ''; +} + +if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) +{ + if (!empty($user->rights->margins->creer)) + { + if ($conf->global->MARGIN_TYPE == "1") + print ''.$langs->trans('BuyingPrice').''; + else + print ''.$langs->trans('CostPrice').''; + } + + if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) + print ''.$langs->trans('MarginRate').''; + if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) + print ''.$langs->trans('MarkRate').''; +} + +// Total HT +print ''.$langs->trans('TotalHTShort').''; + +// Multicurrency +if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print ''.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).''; + +if ($outputalsopricetotalwithtax) print ''.$langs->trans('TotalTTCShort').''; + +print ''; // No width to allow autodim + +print ''; + +print ''; + +if($action == 'selectlines') +{ + print ''; + print ''; + print ''; + print ''; +} + +print "\n"; +print "\n"; +?> + + \ No newline at end of file diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 31db9d0c2b4..f38b8fb10e0 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1647,11 +1647,11 @@ elseif ($id > 0 || ! empty($ref)) } // create intervention model - if ($object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer && (count($object->lines) > 0)) { + if ($object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer && (count($object->lines) > 0) && $conf->global->MAIN_FEATURES_LEVEL >= 2) { print ''; } diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 22cc1036f52..6f1a773b7c1 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE', 'Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION', '10.0.0-beta'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c +if (! defined('DOL_VERSION')) define('DOL_VERSION', '10.0.0'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c if (! defined('EURO')) define('EURO', chr(128)); diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index c36debb9a12..a3e1f43b619 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -42,6 +42,11 @@ class MyObject extends CommonObject */ public $table_element = 'mymodule_myobject'; + /** + * @var string Name of subtable if this object has sub lines + */ + //public $table_element_line = 'mymodule_myobjectline'; + /** * @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ @@ -327,14 +332,14 @@ class MyObject extends CommonObject * * @return int <0 if KO, 0 if not found, >0 if OK */ - /*public function fetchLines() + public function fetchLines() { $this->lines=array(); - // Load lines with object MyObjectLine + $result = $this->fetchLinesCommon(); + return $result; + } - return count($this->lines)?1:0; - }*/ /** * Load list of objects in memory from the database. @@ -355,11 +360,11 @@ class MyObject extends CommonObject $records=array(); - $sql = 'SELECT'; - $sql .= ' t.rowid'; - // TODO Get all fields + $sql = 'SELECT '; + $sql .= $this->getFieldList(); $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; - $sql .= ' WHERE t.entity = '.$conf->entity; + if ($this->ismultientitymanaged) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')'; + else $sql .= ' WHERE 1 = 1'; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -398,11 +403,8 @@ class MyObject extends CommonObject $obj = $this->db->fetch_object($resql); $record = new self($this->db); + $record->setVarsFromFetchObj($obj); - $record->id = $obj->rowid; - // TODO Get other fields - - //var_dump($record->id); $records[$record->id] = $record; $i++; @@ -443,6 +445,25 @@ class MyObject extends CommonObject //return $this->deleteCommon($user, $notrigger, 1); } + /** + * Delete a line of object in database + * + * @param User $user User that delete + * @param int $idline Id of line to delete + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int >0 if OK, <0 if KO + */ + public function deleteLine(User $user, $idline, $notrigger = false) + { + if ($this->status < 0) + { + $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; + return -2; + } + + return $this->deleteLineCommon($user, $idline, $notrigger); + } + /** * Return a link to the object card (with optionaly the picto) * @@ -649,8 +670,8 @@ class MyObject extends CommonObject { $this->lines=array(); - $objectline = new BOMLine($this->db); - $result = $objectline->fetchAll('', '', 0, 0, array('fk_myobject'=>$this->id)); + $objectline = new MyObjectLine($this->db); + $result = $objectline->fetchAll('', '', 0, 0, array('customsql'=>'fk_myobject = '.$this->id)); if (is_numeric($result)) { @@ -661,10 +682,43 @@ class MyObject extends CommonObject else { $this->lines = $result; - return $this->lines(); + return $this->lines; } } + /** + * Create a document onto disk according to template module. + * + * @param string $modele Force template to use ('' to not force) + * @param Translate $outputlangs objet lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @param null|array $moreparams Array to provide more information + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) + { + global $conf,$langs; + + $langs->load("mymodule@mymodule"); + + if (! dol_strlen($modele)) { + + $modele = 'standard'; + + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (! empty($conf->global->MYOBJECT_ADDON_PDF)) { + $modele = $conf->global->MYOBJECT_ADDON_PDF; + } + } + + $modelpath = "core/modules/mymodule/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + } + /** * Action executed by scheduler * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters' @@ -699,14 +753,7 @@ class MyObject extends CommonObject /** * Class MyObjectLine. You can also remove this and generate a CRUD class for lines objects. */ -/* class MyObjectLine { - // @var int ID - public $id; - // @var mixed Sample line property 1 - public $prop1; - // @var mixed Sample line property 2 - public $prop2; + // To complete with content of an object MyObjectLine } -*/ diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 1fc376dfe17..64a0eb008fa 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -73,6 +73,7 @@ $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'myobjectcard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); +//$lineid = GETPOST('lineid', 'int'); // Initialize technical objects $object=new MyObject($db); @@ -159,7 +160,7 @@ if (empty($reshook)) $form=new Form($db); $formfile=new FormFile($db); -llxHeader('', 'MyObject', ''); +llxHeader('', $langs->trans('MyObject'), ''); // Example : Adding jquery code print '