/** * Ajout d'une ligne remise fixe dans la commande, en base * @param idremise Id de la remise fixe * @return int >0 si ok, <0 si ko */ function insert_discount($idremise) { global $langs; include_once DOL_DOCUMENT_ROOT . '/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php'; $this->db->begin(); $remise = new DiscountAbsolute($this->db); $result = $remise->fetch($idremise); if ($result > 0) { if ($remise->fk_facture) { $this->error = $langs->trans("ErrorDiscountAlreadyUsed"); $this->db->rollback(); return -5; } $line = new OrderLine($this->db); $line->fk_commande = $this->id; $line->fk_remise_except = $remise->id; $line->desc = $remise->description; // Description ligne $line->tva_tx = $remise->tva_tx; $line->subprice = -$remise->amount_ht; $line->price = -$remise->amount_ht; $line->fk_product = 0; // Id produit predefini $line->qty = 1; $line->remise = 0; $line->remise_percent = 0; $line->rang = -1; $line->info_bits = 2; $line->total_ht = -$remise->amount_ht; $line->total_tva = -$remise->amount_tva; $line->total_ttc = -$remise->amount_ttc; $result = $line->insert(); if ($result > 0) { $result = $this->update_price(1); if ($result > 0) { $this->db->commit(); return 1; } else { $this->db->rollback(); return -1; } } else { $this->error = $line->error; $this->db->rollback(); return -2; } } else { $this->db->rollback(); return -2; } }
/** * Insert line into database * * @param int $notrigger 1 no triggers * @return int <0 if KO, >0 if OK */ function insert($notrigger = 0) { global $langs, $user, $conf; $error = 0; $pa_ht_isemptystring = empty($this->pa_ht) && $this->pa_ht == ''; // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. dol_syslog(get_class($this) . "::insert rang=" . $this->rang, LOG_DEBUG); // Clean parameters $this->desc = trim($this->desc); if (empty($this->tva_tx)) { $this->tva_tx = 0; } if (empty($this->localtax1_tx)) { $this->localtax1_tx = 0; } if (empty($this->localtax2_tx)) { $this->localtax2_tx = 0; } if (empty($this->localtax1_type)) { $this->localtax1_type = 0; } if (empty($this->localtax2_type)) { $this->localtax2_type = 0; } if (empty($this->total_localtax1)) { $this->total_localtax1 = 0; } if (empty($this->total_localtax2)) { $this->total_localtax2 = 0; } if (empty($this->rang)) { $this->rang = 0; } if (empty($this->remise_percent)) { $this->remise_percent = 0; } if (empty($this->info_bits)) { $this->info_bits = 0; } if (empty($this->subprice)) { $this->subprice = 0; } if (empty($this->special_code)) { $this->special_code = 0; } if (empty($this->fk_parent_line)) { $this->fk_parent_line = 0; } if (empty($this->fk_prev_id)) { $this->fk_prev_id = 'null'; } if (empty($this->situation_percent)) { $this->situation_percent = 0; } if (empty($this->pa_ht)) { $this->pa_ht = 0; } // if buy price not defined, define buyprice as configured in margin admin if ($this->pa_ht == 0 && $pa_ht_isemptystring) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { return $result; } else { $this->pa_ht = $result; } } // Check parameters if ($this->product_type < 0) { $this->error = 'ErrorProductTypeMustBe0orMore'; return -1; } if (!empty($this->fk_product)) { // Check product exists $result = Product::isExistingObject('product', $this->fk_product); if ($result <= 0) { $this->error = 'ErrorProductIdDoesNotExists'; return -1; } } $this->db->begin(); // Insertion dans base de la ligne $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'facturedet'; $sql .= ' (fk_facture, fk_parent_line, label, description, qty,'; $sql .= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; $sql .= ' fk_product, product_type, remise_percent, subprice, fk_remise_except,'; $sql .= ' date_start, date_end, fk_code_ventilation, '; $sql .= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,'; $sql .= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2,'; $sql .= ' situation_percent, fk_prev_id,'; $sql .= ' fk_unit)'; $sql .= " VALUES (" . $this->fk_facture . ","; $sql .= " " . ($this->fk_parent_line > 0 ? "'" . $this->fk_parent_line . "'" : "null") . ","; $sql .= " " . (!empty($this->label) ? "'" . $this->db->escape($this->label) . "'" : "null") . ","; $sql .= " '" . $this->db->escape($this->desc) . "',"; $sql .= " " . price2num($this->qty) . ","; $sql .= " " . price2num($this->tva_tx) . ","; $sql .= " " . price2num($this->localtax1_tx) . ","; $sql .= " " . price2num($this->localtax2_tx) . ","; $sql .= " '" . $this->localtax1_type . "',"; $sql .= " '" . $this->localtax2_type . "',"; $sql .= ' ' . (!empty($this->fk_product) ? $this->fk_product : "null") . ','; $sql .= " " . $this->product_type . ","; $sql .= " " . price2num($this->remise_percent) . ","; $sql .= " " . price2num($this->subprice) . ","; $sql .= ' ' . (!empty($this->fk_remise_except) ? $this->fk_remise_except : "null") . ','; $sql .= " " . (!empty($this->date_start) ? "'" . $this->db->idate($this->date_start) . "'" : "null") . ","; $sql .= " " . (!empty($this->date_end) ? "'" . $this->db->idate($this->date_end) . "'" : "null") . ","; $sql .= ' ' . $this->fk_code_ventilation . ','; $sql .= ' ' . $this->rang . ','; $sql .= ' ' . $this->special_code . ','; $sql .= ' ' . (!empty($this->fk_fournprice) ? $this->fk_fournprice : "null") . ','; $sql .= ' ' . price2num($this->pa_ht) . ','; $sql .= " '" . $this->info_bits . "',"; $sql .= " " . price2num($this->total_ht) . ","; $sql .= " " . price2num($this->total_tva) . ","; $sql .= " " . price2num($this->total_ttc) . ","; $sql .= " " . price2num($this->total_localtax1) . ","; $sql .= " " . price2num($this->total_localtax2); $sql .= ", " . $this->situation_percent; $sql .= ", " . $this->fk_prev_id; $sql .= ", " . (!$this->fk_unit ? 'NULL' : $this->fk_unit); $sql .= ')'; dol_syslog(get_class($this) . "::insert", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX . 'facturedet'); if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $this->id = $this->rowid; $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } // Si fk_remise_except defini, on lie la remise a la facture // ce qui la flague comme "consommee". if ($this->fk_remise_except) { $discount = new DiscountAbsolute($this->db); $result = $discount->fetch($this->fk_remise_except); if ($result >= 0) { // Check if discount was found if ($result > 0) { // Check if discount not already affected to another invoice if ($discount->fk_facture) { $this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id); dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } else { $result = $discount->link_to_invoice($this->rowid, 0); if ($result < 0) { $this->error = $discount->error; dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } } else { $this->error = $langs->trans("ErrorADiscountThatHasBeenRemovedIsIncluded"); dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } else { $this->error = $discount->error; dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINEBILL_INSERT', $user); if ($result < 0) { $this->db->rollback(); return -2; } // End call triggers } $this->db->commit(); return $this->rowid; } else { $this->error = $this->db->error(); $this->db->rollback(); return -2; } }
/** * Return line description translated in outputlangs and encoded into UTF8 * * @param Line $line Current line number (0 = first line, 1 = second line, ...) * @param Translate $outputlangs Object langs for output * @param int $hideref Hide reference * @param int $hidedesc Hide description * @param int $issupplierline Is it a line for a supplier object ? * @return string String with line */ function doc_getlinedesc($line, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0) { global $db, $conf, $langs; $idprod = $line->fk_product; $label = $line->label; if (empty($label)) { $label = $line->libelle; } $desc = $line->desc; if (empty($desc)) { $desc = $line->description; } $ref_supplier = $line->ref_supplier; if (empty($ref_supplier)) { $ref_supplier = $line->ref_fourn; } // TODO Not yet saved for supplier invoices, only supplier orders $note = $line->note; if ($issupplierline) { $prodser = new ProductFournisseur($db); } else { $prodser = new Product($db); } if ($idprod) { $prodser->fetch($idprod); // If a predefined product and multilang and on other lang, we renamed label with label translated if ($conf->global->MAIN_MULTILANGS && $outputlangs->defaultlang != $langs->defaultlang) { if (!empty($prodser->multilangs[$outputlangs->defaultlang]["libelle"]) && $label == $prodser->label) { $label = $prodser->multilangs[$outputlangs->defaultlang]["libelle"]; } if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) { $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"]; } if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) { $note = $prodser->multilangs[$outputlangs->defaultlang]["note"]; } } } // Description short of product line $libelleproduitservice = $label; // Description long of product line if ($desc && $desc != $label) { if ($libelleproduitservice && empty($hidedesc)) { $libelleproduitservice .= "\n"; } if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except) { $discount = new DiscountAbsolute($db); $discount->fetch($line->fk_remise_except); $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $discount->ref_facture_source); } elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except) { $discount = new DiscountAbsolute($db); $discount->fetch($line->fk_remise_except); $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $discount->ref_facture_source); // Add date of deposit if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) { echo ' (' . dol_print_date($discount->datec, 'day', '', $outputlangs) . ')'; } } else { if ($idprod) { if (empty($hidedesc)) { $libelleproduitservice .= $desc; } } else { $libelleproduitservice .= $desc; } } } // If line linked to a product if ($idprod) { // On ajoute la ref if ($prodser->ref) { $prefix_prodserv = ""; $ref_prodserv = ""; if ($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS) { if ($prodser->isservice()) { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service") . " "; } else { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product") . " "; } } if (empty($hideref)) { if ($issupplierline) { $ref_prodserv = $prodser->ref . ' (' . $outputlangs->trans("SupplierRef") . ' ' . $ref_supplier . ')'; } else { $ref_prodserv = $prodser->ref; } // Show local ref only $ref_prodserv .= " - "; } $libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice; } } if ($line->date_start || $line->date_end) { $format = 'day'; // Show duration if exists if ($line->date_start && $line->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($line->date_start, $format, false, $outputlangs), dol_print_date($line->date_end, $format, false, $outputlangs)) . ')'; } if ($line->date_start && !$line->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($line->date_start, $format, false, $outputlangs)) . ')'; } if (!$line->date_start && $line->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($line->date_end, $format, false, $outputlangs)) . ')'; } //print '>'.$outputlangs->charset_output.','.$period; $libelleproduitservice .= "\n" . $period; //print $libelleproduitservice; } return $libelleproduitservice; }
/** * Return line description translated in outputlangs and encoded into htmlentities and with <br> * * @param Object $object Object * @param int $i Current line number (0 = first line, 1 = second line, ...) * @param Translate $outputlangs Object langs for output * @param int $hideref Hide reference * @param int $hidedesc Hide description * @param int $issupplierline Is it a line for a supplier object ? * @return string String with line */ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0) { global $db, $conf, $langs; $idprod = !empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false; $label = !empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : ''); $desc = !empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : ''); $ref_supplier = !empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : ''); // TODO Not yet saved for supplier invoices, only supplier orders $note = !empty($object->lines[$i]->note) ? $object->lines[$i]->note : ''; $dbatch = !empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false; if ($issupplierline) { $prodser = new ProductFournisseur($db); } else { $prodser = new Product($db); } if ($idprod) { $prodser->fetch($idprod); // If a predefined product and multilang and on other lang, we renamed label with label translated if (!empty($conf->global->MAIN_MULTILANGS) && $outputlangs->defaultlang != $langs->defaultlang) { $translatealsoifmodified = !empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED); // By default if value was modified manually, we keep it (no translation because we don't have it) // TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation // ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion). // Set label // If we want another language, and if label is same than default language (we did force it to a specific value), we can use translation. //var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit; $textwasmodified = $label == $prodser->label; if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified)) { $label = $prodser->multilangs[$outputlangs->defaultlang]["label"]; } // Set desc // Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no $textwasmodified = false; if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) { $textwasmodified = strpos(dol_html_entity_decode($desc, ENT_QUOTES | ENT_HTML401), dol_html_entity_decode($prodser->description, ENT_QUOTES | ENT_HTML401)) !== false; } else { $textwasmodified = $desc == $prodser->description; } if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified)) { $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"]; } // Set note $textwasmodified = $note == $prodser->note; if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified)) { $note = $prodser->multilangs[$outputlangs->defaultlang]["note"]; } } } // Description short of product line $libelleproduitservice = $label; // Description long of product line if (!empty($desc) && $desc != $label) { if ($libelleproduitservice && empty($hidedesc)) { $libelleproduitservice .= '__N__'; } if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) { $discount = new DiscountAbsolute($db); $discount->fetch($object->lines[$i]->fk_remise_except); $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $discount->ref_facture_source); } elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) { $discount = new DiscountAbsolute($db); $discount->fetch($object->lines[$i]->fk_remise_except); $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $discount->ref_facture_source); // Add date of deposit if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) { echo ' (' . dol_print_date($discount->datec, 'day', '', $outputlangs) . ')'; } } else { if ($idprod) { if (empty($hidedesc)) { $libelleproduitservice .= $desc; } } else { $libelleproduitservice .= $desc; } } } // If line linked to a product if ($idprod) { // We add ref if ($prodser->ref) { $prefix_prodserv = ""; $ref_prodserv = ""; if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) { if ($prodser->isService()) { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service") . " "; } else { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product") . " "; } } if (empty($hideref)) { if ($issupplierline) { $ref_prodserv = $prodser->ref . ($ref_supplier ? ' (' . $outputlangs->transnoentitiesnoconv("SupplierRef") . ' ' . $ref_supplier . ')' : ''); } else { $ref_prodserv = $prodser->ref; } // Show local ref only if (!empty($libelleproduitservice)) { $ref_prodserv .= " - "; } } $libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice; } } // Add an additional description for the category products if (!empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && !empty($conf->categorie->enabled)) { include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $categstatic = new Categorie($db); // recovering the list of all the categories linked to product $tblcateg = $categstatic->containing($idprod, Categorie::TYPE_PRODUCT); foreach ($tblcateg as $cate) { // Adding the descriptions if they are filled $desccateg = $cate->add_description; if ($desccateg) { $libelleproduitservice .= '__N__' . $desccateg; } } } if (!empty($object->lines[$i]->date_start) || !empty($object->lines[$i]->date_end)) { $format = 'day'; // Show duration if exists if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs), dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')'; } if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)) . ')'; } if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')'; } //print '>'.$outputlangs->charset_output.','.$period; $libelleproduitservice .= "__N__" . $period; //print $libelleproduitservice; } if ($dbatch) { $format = 'day'; foreach ($dbatch as $detail) { $dte = array(); if ($detail->eatby) { $dte[] = $outputlangs->transnoentitiesnoconv('printEatby', dol_print_date($detail->eatby, $format, false, $outputlangs)); } if ($detail->sellby) { $dte[] = $outputlangs->transnoentitiesnoconv('printSellby', dol_print_date($detail->sellby, $format, false, $outputlangs)); } if ($detail->batch) { $dte[] = $outputlangs->transnoentitiesnoconv('printBatch', $detail->batch); } $dte[] = $outputlangs->transnoentitiesnoconv('printQty', $detail->dluo_qty); $libelleproduitservice .= "__N__ " . implode($dte, "-"); } } // Now we convert \n into br if (dol_textishtml($libelleproduitservice)) { $libelleproduitservice = preg_replace('/__N__/', '<br>', $libelleproduitservice); } else { $libelleproduitservice = preg_replace('/__N__/', "\n", $libelleproduitservice); } $libelleproduitservice = dol_htmlentitiesbr($libelleproduitservice, 1); return $libelleproduitservice; }
} } else { $error++; $mesg = '<div class="error">' . $soc->error . '</div>'; } } } else { $mesg = '<div class="error">' . $langs->trans("ErrorFieldFormat", $langs->trans("NewGlobalDiscount")) . '</div>'; } } if (GETPOST("action") == 'confirm_remove' && GETPOST("confirm") == 'yes') { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) $db->begin(); $discount = new DiscountAbsolute($db); $result = $discount->fetch(GETPOST("remid")); $result = $discount->delete($user); if ($result > 0) { $db->commit(); header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . GETPOST('id', 'int')); // To avoid pb whith back exit; } else { $mesg = '<div class="error">' . $discount->error . '</div>'; $db->rollback(); } } /* * View */ $form = new Form($db);
/** * Insert line in database * * @param int $notrigger 1 no triggers * @return int <0 if KO, >0 if OK */ function insert($notrigger = 0) { global $langs, $user, $conf; $error = 0; dol_syslog(get_class($this) . "::insert rang=" . $this->rang, LOG_DEBUG); // Clean parameters $this->desc = trim($this->desc); if (empty($this->tva_tx)) { $this->tva_tx = 0; } if (empty($this->localtax1_tx)) { $this->localtax1_tx = 0; } if (empty($this->localtax2_tx)) { $this->localtax2_tx = 0; } if (empty($this->total_localtax1)) { $this->total_localtax1 = 0; } if (empty($this->total_localtax2)) { $this->total_localtax2 = 0; } if (empty($this->rang)) { $this->rang = 0; } //if (empty($this->remise)) $this->remise=0; if (empty($this->remise_percent)) { $this->remise_percent = 0; } if (empty($this->info_bits)) { $this->info_bits = 0; } if (empty($this->subprice)) { $this->subprice = 0; } //if (empty($this->price)) $this->price=0; if (empty($this->special_code)) { $this->special_code = 0; } if (empty($this->fk_parent_line)) { $this->fk_parent_line = 0; } if (empty($this->pa_ht)) { $this->pa_ht = 0; } // si prix d'achat non renseign� et utilis� pour calcul des marges alors prix achat = prix vente (idem pour remises) if ($this->pa_ht == 0) { if ($this->subprice < 0 || $conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1) { $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } } // Check parameters if ($this->product_type < 0) { return -1; } $this->db->begin(); // Insertion dans base de la ligne $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'facturedet'; $sql .= ' (fk_facture, fk_parent_line, description, qty, tva_tx, localtax1_tx, localtax2_tx,'; $sql .= ' fk_product, product_type, remise_percent, subprice, fk_remise_except,'; $sql .= ' date_start, date_end, fk_code_ventilation, fk_export_compta, '; $sql .= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,'; $sql .= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2)'; $sql .= " VALUES (" . $this->fk_facture . ","; $sql .= " " . ($this->fk_parent_line > 0 ? "'" . $this->fk_parent_line . "'" : "null") . ","; $sql .= " '" . $this->db->escape($this->desc) . "',"; $sql .= " " . price2num($this->qty) . ","; $sql .= " " . price2num($this->tva_tx) . ","; $sql .= " " . price2num($this->localtax1_tx) . ","; $sql .= " " . price2num($this->localtax2_tx) . ","; if ($this->fk_product) { $sql .= "'" . $this->fk_product . "',"; } else { $sql .= 'null,'; } $sql .= " " . $this->product_type . ","; $sql .= " " . price2num($this->remise_percent) . ","; $sql .= " " . price2num($this->subprice) . ","; //$sql.= " ".price2num($this->price).","; //$sql.= " ".($this->remise?price2num($this->remise):'0').","; // Deprecated if ($this->fk_remise_except) { $sql .= $this->fk_remise_except . ","; } else { $sql .= 'null,'; } if ($this->date_start) { $sql .= "'" . $this->db->idate($this->date_start) . "',"; } else { $sql .= 'null,'; } if ($this->date_end) { $sql .= "'" . $this->db->idate($this->date_end) . "',"; } else { $sql .= 'null,'; } $sql .= ' ' . $this->fk_code_ventilation . ','; $sql .= ' ' . $this->fk_export_compta . ','; $sql .= ' ' . $this->rang . ','; $sql .= ' ' . $this->special_code . ','; if (isset($this->fk_fournprice)) { $sql .= ' ' . $this->fk_fournprice . ','; } else { $sql .= ' null,'; } if (isset($this->pa_ht)) { $sql .= ' ' . price2num($this->pa_ht) . ','; } else { $sql .= ' null,'; } $sql .= " '" . $this->info_bits . "',"; $sql .= " " . price2num($this->total_ht) . ","; $sql .= " " . price2num($this->total_tva) . ","; $sql .= " " . price2num($this->total_ttc) . ","; $sql .= " " . price2num($this->total_localtax1) . ","; $sql .= " " . price2num($this->total_localtax2); $sql .= ')'; dol_syslog(get_class($this) . "::insert sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX . 'facturedet'); // Si fk_remise_except defini, on lie la remise a la facture // ce qui la flague comme "consommee". if ($this->fk_remise_except) { $discount = new DiscountAbsolute($this->db); $result = $discount->fetch($this->fk_remise_except); if ($result >= 0) { // Check if discount was found if ($result > 0) { // Check if discount not already affected to another invoice if ($discount->fk_facture) { $this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id); dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } else { $result = $discount->link_to_invoice($this->rowid, 0); if ($result < 0) { $this->error = $discount->error; dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } } else { $this->error = $langs->trans("ErrorADiscountThatHasBeenRemovedIsIncluded"); dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } else { $this->error = $discount->error; dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } if (!$notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('LINEBILL_INSERT', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } $this->db->commit(); return $this->rowid; } else { $this->error = $this->db->error(); dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -2; } }
/** * * Add facture Payment * * @param array $aryTicket Ticket data array */ private function addPaymentFac($aryTicket) { global $db, $langs, $conf; require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; $now = dol_now(); $userstatic = new User($db); $error = 0; if (!$aryTicket['employeeId']) { $employee = $_SESSION['uid']; } else { $employee = $aryTicket['employeeId']; } $userstatic->fetch($employee); $max_ite = 3; if ($aryTicket['convertDis']) { require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php'; $object = new Facture($db); $object->fetch($aryTicket['id']); $object->fetch_thirdparty(); // Check if there is already a discount (protection to avoid duplicate creation when resubmit post) $discountcheck = new DiscountAbsolute($db); $result = $discountcheck->fetch(0, $object->id); $canconvert = 0; if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->paye == 0 && empty($discountcheck->id)) { $canconvert = 1; } // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc) if ($canconvert) { $db->begin(); // Boucle sur chaque taux de tva $i = 0; foreach ($object->lines as $line) { $amount_ht[$line->tva_tx] += $line->total_ht; $amount_tva[$line->tva_tx] += $line->total_tva; $amount_ttc[$line->tva_tx] += $line->total_ttc; $i++; } // Insert one discount by VAT rate category $discount = new DiscountAbsolute($db); if ($object->type == Facture::TYPE_CREDIT_NOTE) { $discount->description = $langs->trans('DiscountOf', $object->ref); } $discount->tva_tx = abs($object->total_ttc); $discount->fk_soc = $object->socid; $discount->fk_facture_source = $object->id; $error = 0; foreach ($amount_ht as $tva_tx => $xxx) { $discount->amount_ht = abs($amount_ht[$tva_tx]); $discount->amount_tva = abs($amount_tva[$tva_tx]); $discount->amount_ttc = abs($amount_ttc[$tva_tx]); $discount->tva_tx = abs($tva_tx); $paiement_id = $discount->create($userstatic); if ($paiement_id < 0) { $error++; break; } } if (empty($error)) { // Classe facture $paiement_id = $object->set_paid($user); if ($result >= 0) { //$mesgs[]='OK'.$discount->id; $db->commit(); } else { $db->rollback(); } } else { $db->rollback(); } } } else { if ($aryTicket['type'] == 1) { if ($aryTicket['total'] > $aryTicket['customerpay'] && $aryTicket['difpayment'] == 0) { dol_include_once('/rewards/class/rewards.class.php'); $reward = new Rewards($db); $facture = new Facture($db); $facture->fetch($aryTicket['id']); $modepay[4] = dol_getIdFromCode($db, 'PNT', 'c_paiement'); $amount[4] = $aryTicket['total'] - $aryTicket['customerpay']; $result = $reward->create($facture, price2num($amount[4]) / $conf->global->REWARDS_DISCOUNT); $max_ite++; $amount[4] = $amount[4] * -1; //TODO tot molt bonico, pero que pasa si no gaste punts? } $aryTicket['total'] = $aryTicket['total'] * -1; $aryTicket['customerpay1'] = $aryTicket['customerpay1'] * -1; $aryTicket['customerpay2'] = $aryTicket['customerpay2'] * -1; $aryTicket['customerpay3'] = $aryTicket['customerpay3'] * -1; } $cash = new Cash($db); $terminal = $_SESSION['TERMINAL_ID']; $cash->fetch($terminal); if ($aryTicket['customerpay1'] != 0) { $bankaccountid[1] = $cash->fk_paycash; $modepay[1] = $cash->fk_modepaycash; $amount[1] = $aryTicket['customerpay1'] + ($aryTicket['difpayment'] < 0 ? $aryTicket['difpayment'] : 0); } if ($aryTicket['customerpay2'] != 0) { $bankaccountid[2] = $cash->fk_paybank; $modepay[2] = $cash->fk_modepaybank; $amount[2] = $aryTicket['customerpay2']; } if ($aryTicket['customerpay3'] != 0) { $bankaccountid[3] = $cash->fk_paybank_extra; $modepay[3] = $cash->fk_modepaybank_extra; $amount[3] = $aryTicket['customerpay3']; } //Añadir el posible pago de puntos if ($aryTicket['points'] > 0) { dol_include_once('/rewards/class/rewards.class.php'); $reward = new Rewards($db); $facture = new Facture($db); $facture->fetch($aryTicket['id']); $res = $reward->usePoints($facture, $aryTicket['points']); } $i = 1; $payment = new Paiement($db); while ($i <= $max_ite) { $payment->datepaye = $now; $payment->bank_account = $bankaccountid[$i]; $payment->amounts[$aryTicket['id']] = $amount[$i]; $payment->note = $langs->trans("Payment") . ' ' . $langs->trans("Facture") . ' ' . $aryTicket['ref']; $payment->paiementid = $modepay[$i]; $payment->num_paiement = ''; if ($amount[$i] != 0) { $paiement_id = $payment->create($userstatic, 1); if ($paiement_id > 0) { if ($payment->paiementid != dol_getIdFromCode($db, 'PNT', 'c_paiement')) { $result = $payment->addPaymentToBank($userstatic, 'payment', '(CustomerFacturePayment)', $bankaccountid[$i], $aryTicket['customerId'], '', ''); if ($result < 0) { $error++; } } } else { $error++; } } $i++; } } if ($error > 0) { return -1; } else { return 1; } //$paiement_id; }
function _createAvoir(&$PDOdb, &$db, &$user, &$conf, &$langs) { dol_include_once('/compta/facture/class/facture.class.php'); dol_include_once('/core/class/discount.class.php'); $sql = _getSql2(); $PDOdb->Execute($sql); $TFacnumberFetchError = array(); $TFacnumberCreateError = array(); $TDiscountCreateError = array(); $nbValidate = 0; while ($row = $PDOdb->Get_line()) { $fk_soc = $row->fk_soc; $facnumber = $row->facnumber; $factureImpayee = new Facture($db); if ($factureImpayee->fetch(null, $facnumber) <= 0) { $TFacnumberFetchError[] = $facnumber; continue; } $dateinvoice = dol_mktime(12, 0, 0, date('m'), date('d'), date('Y')); $facture = new Facture($db); $facture->socid = $fk_soc; $facture->fk_facture_source = $factureImpayee->id; $facture->type = Facture::TYPE_CREDIT_NOTE; $facture->date = $dateinvoice; if ($facture->create($user) <= 0) { $TFacnumberCreateError[] = $facnumber; continue; } foreach ($factureImpayee->lines as $line) { $line->fk_facture = $facture->id; $line->subprice = -$line->subprice; // invert price for object $line->pa_ht = -$line->pa_ht; $line->total_ht = -$line->total_ht; $line->total_tva = -$line->total_tva; $line->total_ttc = -$line->total_ttc; $line->total_localtax1 = -$line->total_localtax1; $line->total_localtax2 = -$line->total_localtax2; $line->insert(); $facture->lines[] = $line; // insert new line in current object } $facture->update_price(1); $facture->validate($user); $discountcheck = new DiscountAbsolute($db); $result = $discountcheck->fetch(0, $facture->id); if (!empty($discountcheck->id)) { //can't convert $facture->delete(); continue; } $i = 0; $amount_ht = $amount_tva = $amount_ttc = array(); foreach ($facture->lines as $line) { if ($line->total_ht != 0) { // no need to create discount if amount is null $amount_ht[$line->tva_tx] += $line->total_ht; $amount_tva[$line->tva_tx] += $line->total_tva; $amount_ttc[$line->tva_tx] += $line->total_ttc; $i++; } } // Insert one discount by VAT rate category $discount = new DiscountAbsolute($db); $discount->description = '(CREDIT_NOTE)'; $discount->tva_tx = abs($facture->total_ttc); $discount->fk_soc = $facture->socid; $discount->fk_facture_source = $facture->id; foreach ($amount_ht as $tva_tx => $xxx) { $discount->amount_ht = abs($amount_ht[$tva_tx]); $discount->amount_tva = abs($amount_tva[$tva_tx]); $discount->amount_ttc = abs($amount_ttc[$tva_tx]); $discount->tva_tx = abs($tva_tx); $result = $discount->create($user); if ($result < 0) { $TDiscountCreateError[] = $facnumber; $error++; break; } $result = $facture->set_paid($user); $result = $discount->link_to_invoice(0, $factureImpayee->id); $r = $factureImpayee->set_paid($user); } /******/ $nbValidate++; } if ($nbValidate) { setEventMessages($langs->trans('sendinvoicetoadherentAvoirValidate', $nbValidate), null); } if (count($TFacnumberFetchError) > 0) { setEventMessages($langs->trans('sendinvoicetoadherentErrorFetchFacture', count($TFacnumberFetchError)), null, 'errors'); } if (count($TFacnumberCreateError) > 0) { setEventMessages($langs->trans('sendinvoicetoadherentErrorCreateAvoir', count($TFacnumberCreateError)), null, 'errors'); } $_SESSION['SENDTOINVOICETOADHERENT_TFETCHERROR'] = $TFacnumberFetchError; $_SESSION['SENDTOINVOICETOADHERENT_TCREATEERROR'] = $TFacnumberCreateError; header('Location: ' . dol_buildpath('/sendinvoicetoadherent/sendinvoicetoadherent.php?action=listAvoir', 2)); exit; }
/** * Return HTML with a line of table array of source object lines * TODO Move this and previous function into output html class file (htmlline.class.php). * If lines are into a template, title must also be into a template * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. * * @param array $line Line * @param string $var Var * @return void */ function printOriginLine($line, $var) { global $conf, $langs, $bc; //var_dump($line); $date_start = $line->date_debut_prevue; if ($line->date_debut_reel) { $date_start = $line->date_debut_reel; } $date_end = $line->date_fin_prevue; if ($line->date_fin_reel) { $date_end = $line->date_fin_reel; } $this->tpl['label'] = ''; if (!empty($line->fk_parent_line)) { $this->tpl['label'] .= img_picto('', 'rightarrow'); } if (($line->info_bits & 2) == 2) { $discount = new DiscountAbsolute($this->db); $discount->fk_soc = $this->socid; $this->tpl['label'] .= $discount->getNomUrl(0, 'discount'); } else { if ($line->fk_product) { $productstatic = new Product($this->db); $productstatic->id = $line->fk_product; $productstatic->ref = $line->ref; $productstatic->type = $line->fk_product_type; $this->tpl['label'] .= $productstatic->getNomUrl(1); $this->tpl['label'] .= $line->label ? ' - ' . $line->label : ''; // Dates if ($line->product_type == 1 && ($date_start || $date_end)) { $this->tpl['label'] .= get_date_range($date_start, $date_end); } } else { $this->tpl['label'] .= $line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product')); $this->tpl['label'] .= $line->label ? ' ' . $line->label : ''; // Dates if ($line->product_type == 1 && ($date_start || $date_end)) { $this->tpl['label'] .= get_date_range($date_start, $date_end); } } } if ($line->desc) { if ($line->desc == '(CREDIT_NOTE)') { $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); } elseif ($line->desc == '(DEPOSIT)') { $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); } else { $this->tpl['description'] = dol_trunc($line->desc, 60); } } else { $this->tpl['description'] = ' '; } $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); $this->tpl['price'] = price($line->subprice); $this->tpl['qty'] = ($line->info_bits & 2) != 2 ? $line->qty : ' '; $this->tpl['remise_percent'] = ($line->info_bits & 2) != 2 ? vatrate($line->remise_percent, true) : ' '; // 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')); foreach ($dirtpls as $reldir) { $res = @(include dol_buildpath($reldir . '/originproductline.tpl.php')); if ($res) { break; } } }
if ($line->description == '(DEPOSIT)') { $txt = $langs->trans("Deposit"); } //else $txt=$langs->trans("Discount"); print $txt; ?> </a> <?php if ($line->description) { if ($line->description == '(CREDIT_NOTE)' && $objp->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)' && $objp->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) . ')'; } } 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') : ''); // Show range echo get_date_range($line->date_start, $line->date_end, $format);
/** * testDiscountDelete * * @param int $id Id of discount * @return int * * @depends testDiscountFetch * The depends says test is run only if previous is ok */ public function testDiscountDelete($id) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new DiscountAbsolute($this->savdb); $result=$localobject->fetch($id); $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0); return $result; }
/** * Return HTML with a line of table array of source object lines * TODO Move this and previous function into output html class file (htmlline.class.php). * If lines are into a template, title must also be into a template * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. * @param line * @param var */ function printOriginLine($line, $var) { global $langs, $bc; //var_dump($line); $date_start = $line->date_debut_prevue; if ($line->date_debut_reel) { $date_start = $line->date_debut_reel; } $date_end = $line->date_fin_prevue; if ($line->date_fin_reel) { $date_end = $line->date_fin_reel; } $this->tpl['label'] = ''; if (!empty($line->fk_parent_line)) { $this->tpl['label'] .= img_picto('', 'rightarrow'); } if (($line->info_bits & 2) == 2) { $discount = new DiscountAbsolute($db); $discount->fk_soc = $this->socid; $this->tpl['label'] .= $discount->getNomUrl(0, 'discount'); } else { if ($line->fk_product) { $productstatic = new Product($this->db); $productstatic->id = $line->fk_product; $productstatic->ref = $line->ref; $productstatic->type = $line->fk_product_type; $this->tpl['label'] .= $productstatic->getNomUrl(1); $this->tpl['label'] .= $line->label ? ' - ' . $line->label : ''; // Dates if ($line->product_type == 1 && ($date_start || $date_end)) { $this->tpl['label'] .= get_date_range($date_start, $date_end); } } else { $this->tpl['label'] .= $line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product')); $this->tpl['label'] .= $line->label ? ' ' . $line->label : ''; // Dates if ($line->product_type == 1 && ($date_start || $date_end)) { $this->tpl['label'] .= get_date_range($date_start, $date_end); } } } if ($line->desc) { if ($line->desc == '(CREDIT_NOTE)') { $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); } elseif ($line->desc == '(DEPOSIT)') { $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); } else { $this->tpl['description'] = dol_trunc($line->desc, 60); } } else { $this->tpl['description'] = ' '; } $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); $this->tpl['price'] = price($line->subprice); $this->tpl['qty'] = ($line->info_bits & 2) != 2 ? $line->qty : ' '; $this->tpl['remise_percent'] = ($line->info_bits & 2) != 2 ? vatrate($line->remise_percent, true) : ' '; include DOL_DOCUMENT_ROOT . '/core/tpl/originproductline.tpl.php'; }
/** * Insert line into database * * @param int $notrigger 1 no triggers * @return int <0 if KO, >0 if OK */ function insert($notrigger = 0) { global $langs, $user, $conf; $error = 0; dol_syslog(get_class($this) . "::insert rang=" . $this->rang, LOG_DEBUG); // Clean parameters $this->desc = trim($this->desc); if (empty($this->tva_tx)) { $this->tva_tx = 0; } if (empty($this->localtax1_tx)) { $this->localtax1_tx = 0; } if (empty($this->localtax2_tx)) { $this->localtax2_tx = 0; } if (empty($this->localtax1_type)) { $this->localtax1_type = 0; } if (empty($this->localtax2_type)) { $this->localtax2_type = 0; } if (empty($this->total_localtax1)) { $this->total_localtax1 = 0; } if (empty($this->total_localtax2)) { $this->total_localtax2 = 0; } if (empty($this->rang)) { $this->rang = 0; } if (empty($this->remise_percent)) { $this->remise_percent = 0; } if (empty($this->info_bits)) { $this->info_bits = 0; } if (empty($this->subprice)) { $this->subprice = 0; } if (empty($this->special_code)) { $this->special_code = 0; } if (empty($this->fk_parent_line)) { $this->fk_parent_line = 0; } if (empty($this->pa_ht)) { $this->pa_ht = 0; } // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente if ($this->pa_ht == 0) { if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100); } } // Check parameters if ($this->product_type < 0) { $this->error = 'ErrorProductTypeMustBe0orMore'; return -1; } if (!empty($this->fk_product)) { // Check product exists $result = Product::isExistingObject('product', $this->fk_product); if ($result <= 0) { $this->error = 'ErrorProductIdDoesNotExists'; return -1; } } // POS or by external module, take lowest buying price if (!empty($this->fk_product) && empty($this->fk_fournprice) && empty($this->pa_ht)) { include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php'; $productFournisseur = new ProductFournisseur($this->db); $productFournisseur->find_min_price_product_fournisseur($this->fk_product); $this->fk_fournprice = $productFournisseur->product_fourn_price_id; } $this->db->begin(); // Insertion dans base de la ligne $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'facturedet'; $sql .= ' (fk_facture, fk_parent_line, label, description, qty,'; $sql .= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; $sql .= ' fk_product, product_type, remise_percent, subprice, fk_remise_except,'; $sql .= ' date_start, date_end, fk_code_ventilation, '; $sql .= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,'; $sql .= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2)'; $sql .= " VALUES (" . $this->fk_facture . ","; $sql .= " " . ($this->fk_parent_line > 0 ? "'" . $this->fk_parent_line . "'" : "null") . ","; $sql .= " " . (!empty($this->label) ? "'" . $this->db->escape($this->label) . "'" : "null") . ","; $sql .= " '" . $this->db->escape($this->desc) . "',"; $sql .= " " . price2num($this->qty) . ","; $sql .= " " . price2num($this->tva_tx) . ","; $sql .= " " . price2num($this->localtax1_tx) . ","; $sql .= " " . price2num($this->localtax2_tx) . ","; $sql .= " '" . $this->localtax1_type . "',"; $sql .= " '" . $this->localtax2_type . "',"; $sql .= ' ' . (!empty($this->fk_product) ? $this->fk_product : "null") . ','; $sql .= " " . $this->product_type . ","; $sql .= " " . price2num($this->remise_percent) . ","; $sql .= " " . price2num($this->subprice) . ","; $sql .= ' ' . (!empty($this->fk_remise_except) ? $this->fk_remise_except : "null") . ','; $sql .= " " . (!empty($this->date_start) ? "'" . $this->db->idate($this->date_start) . "'" : "null") . ","; $sql .= " " . (!empty($this->date_end) ? "'" . $this->db->idate($this->date_end) . "'" : "null") . ","; $sql .= ' ' . $this->fk_code_ventilation . ','; $sql .= ' ' . $this->rang . ','; $sql .= ' ' . $this->special_code . ','; $sql .= ' ' . (!empty($this->fk_fournprice) ? $this->fk_fournprice : "null") . ','; $sql .= ' ' . price2num($this->pa_ht) . ','; $sql .= " '" . $this->info_bits . "',"; $sql .= " " . price2num($this->total_ht) . ","; $sql .= " " . price2num($this->total_tva) . ","; $sql .= " " . price2num($this->total_ttc) . ","; $sql .= " " . price2num($this->total_localtax1) . ","; $sql .= " " . price2num($this->total_localtax2); $sql .= ')'; dol_syslog(get_class($this) . "::insert", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX . 'facturedet'); if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $this->id = $this->rowid; $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } // Si fk_remise_except defini, on lie la remise a la facture // ce qui la flague comme "consommee". if ($this->fk_remise_except) { $discount = new DiscountAbsolute($this->db); $result = $discount->fetch($this->fk_remise_except); if ($result >= 0) { // Check if discount was found if ($result > 0) { // Check if discount not already affected to another invoice if ($discount->fk_facture) { $this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id); dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } else { $result = $discount->link_to_invoice($this->rowid, 0); if ($result < 0) { $this->error = $discount->error; dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } } else { $this->error = $langs->trans("ErrorADiscountThatHasBeenRemovedIsIncluded"); dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } else { $this->error = $discount->error; dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINEBILL_INSERT', $user); if ($result < 0) { $this->db->rollback(); return -2; } // End call triggers } $this->db->commit(); return $this->rowid; } else { $this->error = $this->db->error(); $this->db->rollback(); return -2; } }
} else { print '<td>'; print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne if (($objp->info_bits & 2) == 2) { print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->socid.'">'; print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); print '</a>'; if ($objp->description) { if ($objp->description == '(CREDIT_NOTE)') { $discount=new DiscountAbsolute($db); $discount->fetch($objp->fk_remise_except); print ' - '.$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); } else { print ' - '.nl2br($objp->description); } } } else { if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); print $text.' '.nl2br($objp->description); // Show range
} $head = facture_prepare_head($fac); dol_fiche_head($head, 'standingorders', $langs->trans('InvoiceCustomer'),0,'bill'); /* * Facture */ print '<table class="border" width="100%">'; // Ref print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="5">'; $morehtmlref=''; $discount=new DiscountAbsolute($db); $result=$discount->fetch(0,$fac->id); if ($result > 0) { $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')'; } if ($result < 0) { dol_print_error('',$discount->error); } print $html->showrefnav($fac,'ref','',1,'facnumber','ref',$morehtmlref); print "</td></tr>"; // Third party print '<tr><td>'.$langs->trans('Company').'</td>'; print '<td colspan="5">'.$soc->getNomUrl(1,'compta'); print ' (<a href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$fac->socid.'">'.$langs->trans('OtherBills').'</a>)</td>';
$formconfirm .= $hookmanager->resPrint; } elseif ($reshook > 0) { $formconfirm = $hookmanager->resPrint; } } // Print form confirm print $formconfirm; // Invoice content print '<table class="border" width="100%">'; $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php' . (!empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; // Ref print '<tr><td width="20%">' . $langs->trans('Ref') . '</td>'; print '<td colspan="5">'; $morehtmlref = ''; $discount = new DiscountAbsolute($db); $result = $discount->fetch(0, $object->id); if ($result > 0) { $morehtmlref = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", $discount->getNomUrl(1, 'discount')) . ')'; } if ($result < 0) { dol_print_error('', $discount->error); } print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref); print '</td></tr>'; // Ref customer print '<tr><td width="20%">'; print '<table class="nobordernopadding" width="100%"><tr><td>'; print $langs->trans('RefCustomer'); print '</td>'; if ($action != 'refclient' && !empty($object->brouillon)) { print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=refclient&id=' . $object->id . '">' . img_edit($langs->trans('Modify')) . '</a></td>';
/** * Return line description translated in outputlangs and encoded in UTF8 * @param object Object * @param i Current line number * @param outputlangs Object langs for output * @param hideref Hide reference * @param hidedesc Hide description * @param issupplierline Is it a line for a supplier object ? * @return string String with line */ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0) { global $db, $conf, $langs; $idprod = $object->lines[$i]->fk_product; $label = $object->lines[$i]->label; if (empty($label)) { $label = $object->lines[$i]->libelle; } $desc = $object->lines[$i]->desc; if (empty($desc)) { $desc = $object->lines[$i]->description; } $ref_supplier = $object->lines[$i]->ref_supplier; if (empty($ref_supplier)) { $ref_supplier = $object->lines[$i]->ref_fourn; } // TODO Not yeld saved for supplier invoices, only supplier orders $note = $object->lines[$i]->note; if ($issupplierline) { $prodser = new ProductFournisseur($db); } else { $prodser = new Product($db); } if ($idprod) { $prodser->fetch($idprod); // If a predefined product and multilang and on other lang, we renamed label with label translated if ($conf->global->MAIN_MULTILANGS && $outputlangs->defaultlang != $langs->defaultlang) { if (!empty($prodser->multilangs[$outputlangs->defaultlang]["libelle"])) { $label = $prodser->multilangs[$outputlangs->defaultlang]["libelle"]; } if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"])) { $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"]; } if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"])) { $note = $prodser->multilangs[$outputlangs->defaultlang]["note"]; } } } // Description short of product line $libelleproduitservice = $label; // Description long of product line if ($desc && $desc != $label) { if ($libelleproduitservice && empty($hidedesc)) { $libelleproduitservice .= "<br />"; } if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except) { $discount = new DiscountAbsolute($db); $discount->fetch($object->lines[$i]->fk_remise_except); $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $discount->ref_facture_source); } elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) { $discount = new DiscountAbsolute($db); $discount->fetch($object->lines[$i]->fk_remise_except); $libelleproduitservice = $outputlangs->transnoentities("DiscountFromDeposit", $discount->ref_facture_source); // Add date of deposit if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) { echo ' (' . dol_print_date($discount->datec, 'day', '', $outputlangs) . ')'; } } else { if ($idprod) { if (empty($hidedesc)) { $libelleproduitservice .= dol_htmlentitiesbr($desc, 1); } } else { $libelleproduitservice .= dol_htmlentitiesbr($desc, 1); } } } // If line linked to a product if ($idprod) { // On ajoute la ref if ($prodser->ref) { $prefix_prodserv = ""; $ref_prodserv = ""; if ($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS) { if ($prodser->isservice()) { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service") . " "; } else { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product") . " "; } } if (empty($hideref)) { if ($issupplierline) { $ref_prodserv = $prodser->ref . ' (' . $outputlangs->trans("SupplierRef") . ' ' . $ref_supplier . ')'; } else { $ref_prodserv = $prodser->ref; } // Show local ref only $ref_prodserv .= " - "; } $libelleproduitservice = $prefix_prodserv . $ref_prodserv . $libelleproduitservice; } } $libelleproduitservice = dol_htmlentitiesbr($libelleproduitservice, 1); if ($object->lines[$i]->date_start || $object->lines[$i]->date_end) { // Show duration if exists if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs), dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')'; } if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)) . ')'; } if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end) { $period = '(' . $outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)) . ')'; } //print '>'.$outputlangs->charset_output.','.$period; $libelleproduitservice .= "<br>" . dol_htmlentitiesbr($period, 1); //print $libelleproduitservice; } // Note that we used here current custom and origin country code. /* Fix, this must be done when saving line if (! empty($prodser->customcode) || ! empty($prodser->country_code)) { //var_dump($prodser);exit; $tmptxt='('; if (! empty($prodser->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prodser->customcode; if (! empty($prodser->customcode) && ! empty($prodser->country_code)) $tmptxt.=' - '; if (! empty($prodser->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prodser->country_code,0,$db,$outputlangs,0); $tmptxt.=')'; $libelleproduitservice.="<br>".$tmptxt; }*/ return $libelleproduitservice; }