diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 7baf187756c..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); @@ -149,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 82c5efbb71b..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 @@ -76,7 +74,6 @@ $objectline = new BOMLine($this->db); { print (! empty($line->description) && $line->description!=$line->product_label)?'
'.dol_htmlentitiesbr($line->description):''; } - } ?> @@ -96,43 +93,14 @@ $objectline = new BOMLine($this->db); print ''; } ?> - - remise_percent) && $line->special_code != 3) { ?> - remise_percent, $langs); - ?> - -   - global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); - - ?> - - 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 '
'; - } - ?> - - + + efficiency; + ?> + statut == 0 && ($object_rights->creer) && $action != 'selectlines' ) { ?> + + if ($this->statut == 0 && ($object_rights->write) && $action != 'selectlines' ) { ?> info_bits & 2) == 2 || ! empty($disableedit)) { ?> @@ -145,7 +113,7 @@ $objectline = new BOMLine($this->db); 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/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 02c7a9ca6dd..9852e2f2fb0 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3916,7 +3916,7 @@ abstract class CommonObject */ public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir = '/core/tpl') { - global $conf, $hookmanager, $langs, $user, $object; + global $conf, $hookmanager, $langs, $user, $object, $form; // TODO We should not use global var for this global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; @@ -4075,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)) @@ -7529,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/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index c85ceb3c18b..a3e1f43b619 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -445,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) * @@ -667,6 +686,39 @@ class MyObject extends CommonObject } } + /** + * 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' diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 159dc897fa3..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 '