--- /tmp/dsg/dolibarr/htdocs/comm/propal/github_card.php +++ /tmp/dsg/dolibarr/htdocs/comm/propal/client_card.php @@ -13,7 +13,6 @@ * Copyright (C) 2014 Ferran Marcet * Copyright (C) 2016 Marcos García * Copyright (C) 2018-2019 Frédéric France - * Copyright (C) 2020 Nicolas ZABOURI * * 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 @@ -69,7 +68,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $origin = GETPOST('origin', 'alpha'); $originid = GETPOST('originid', 'int'); @@ -162,30 +161,30 @@ if (!GETPOST('socid', 3)) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); - } else { + } + else + { if ($object->id > 0) { if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY)) { //Get difference between old and new delivery date and change lines according to difference - $date_delivery = dol_mktime(12, 0, 0, + $date_delivery = dol_mktime(12, 0, 0, GETPOST('date_deliverymonth', 'int'), GETPOST('date_deliveryday', 'int'), GETPOST('date_deliveryyear', 'int') ); - $date_delivery_old = (empty($object->delivery_date) ? $object->date_livraison : $object->delivery_date); - if (!empty($date_delivery_old) && !empty($date_delivery)) + if (!empty($object->date_livraison) && !empty($date_delivery)) { //Attempt to get the date without possible hour rounding errors - $old_date_delivery = dol_mktime(12, 0, 0, - dol_print_date($date_delivery_old, '%m'), - dol_print_date($date_delivery_old, '%d'), - dol_print_date($date_delivery_old, '%Y') + $old_date_delivery = dol_mktime(12, 0, 0, + dol_print_date($object->date_livraison, '%m'), + dol_print_date($object->date_livraison, '%d'), + dol_print_date($object->date_livraison, '%Y') ); //Calculate the difference and apply if necessary $difference = $date_delivery - $old_date_delivery; if ($difference != 0) { $object->date_livraison = $date_delivery; - $object->delivery_date = $date_delivery; foreach ($object->lines as $line) { if (isset($line->date_start)) $line->date_start = $line->date_start + $difference; @@ -205,7 +204,9 @@ } } } - } // Delete proposal + } + + // Delete proposal elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) { $result = $object->delete($user); @@ -216,7 +217,9 @@ $langs->load("errors"); setEventMessages($object->error, $object->errors, 'errors'); } - } // Remove line + } + + // Remove line elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { $result = $object->deleteline($lineid); @@ -233,13 +236,14 @@ $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records - if ($ret > 0) $object->fetch_thirdparty(); - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit(); - } // Validation + } + + // Validation elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) { $result = $object->valid($user); @@ -255,11 +259,8 @@ $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - $model = $object->model_pdf; + $model = $object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - if ($ret > 0) { - $object->fetch_thirdparty(); - } $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } @@ -268,7 +269,9 @@ if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors'); else setEventMessages($langs->trans($object->error), null, 'errors'); } - } elseif ($action == 'setdate' && $usercancreate) + } + + elseif ($action == 'setdate' && $usercancreate) { $datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -282,17 +285,21 @@ if ($result < 0) dol_print_error($db, $object->error); } - } elseif ($action == 'setecheance' && $usercancreate) + } + elseif ($action == 'setecheance' && $usercancreate) { $result = $object->set_echeance($user, dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear'])); if ($result < 0) dol_print_error($db, $object->error); - } elseif ($action == 'setdate_livraison' && $usercancreate) - { - $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, $_POST['date_livraisonmonth'], $_POST['date_livraisonday'], $_POST['date_livraisonyear'])); + } + elseif ($action == 'setdate_livraison' && $usercancreate) + { + $result = $object->set_date_livraison($user, dol_mktime(12, 0, 0, $_POST['date_livraisonmonth'], $_POST['date_livraisonday'], $_POST['date_livraisonyear'])); if ($result < 0) dol_print_error($db, $object->error); - } // Positionne ref client + } + + // Positionne ref client elseif ($action == 'setref_client' && $usercancreate) { $result = $object->set_ref_client($user, GETPOST('ref_client')); @@ -300,11 +307,15 @@ { setEventMessages($object->error, $object->errors, 'errors'); } - } // Set incoterm + } + + // Set incoterm elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled) && $usercancreate) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - } // Create proposal + } + + // Create proposal elseif ($action == 'add' && $usercancreate) { $object->socid = $socid; @@ -342,9 +353,7 @@ if ($object->fetch(GETPOST('copie_propal', 'int')) > 0) { $object->ref = GETPOST('ref'); $object->datep = $datep; - $object->date = $datep; - $object->date_livraison = $date_delivery; // deprecated - $object->delivery_date = $date_delivery; + $object->date_livraison = $date_delivery; $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->fk_delivery_address = GETPOST('fk_address', 'int'); @@ -356,16 +365,18 @@ $object->remise_percent = GETPOST('remise_percent'); $object->remise_absolue = GETPOST('remise_absolue'); $object->socid = GETPOST('socid', 'int'); - $object->contact_id = GETPOST('contactid', 'int'); + $object->contactid = GETPOST('contactid', 'int'); $object->fk_project = GETPOST('projectid', 'int'); - $object->model_pdf = GETPOST('model', 'alphanohtml'); + $object->modelpdf = GETPOST('model'); $object->author = $user->id; // deprecated - $object->user_author_id = $user->id; - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->note_public = GETPOST('note_public', 'restricthtml'); + $object->note_private = GETPOST('note_private', 'none'); + $object->note_public = GETPOST('note_public', 'none'); $object->statut = Propal::STATUS_DRAFT; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + + // the create is done below and further more the existing create_from function is quite hilarating + //$id = $object->create_from($user); } else { setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), null, 'errors'); } @@ -373,23 +384,21 @@ $object->ref = GETPOST('ref'); $object->ref_client = GETPOST('ref_client'); $object->datep = $datep; - $object->date = $datep; $object->date_livraison = $date_delivery; - $object->delivery_date = $date_delivery; - $object->availability_id = GETPOST('availability_id', 'int'); - $object->demand_reason_id = GETPOST('demand_reason_id', 'int'); - $object->fk_delivery_address = GETPOST('fk_address', 'int'); + $object->availability_id = GETPOST('availability_id'); + $object->demand_reason_id = GETPOST('demand_reason_id'); + $object->fk_delivery_address = GETPOST('fk_address'); $object->shipping_method_id = GETPOST('shipping_method_id', 'int'); - $object->duree_validite = price2num(GETPOST('duree_validite', 'alpha')); - $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int'); - $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); + $object->duree_validite = GETPOST('duree_validite'); + $object->cond_reglement_id = GETPOST('cond_reglement_id'); + $object->mode_reglement_id = GETPOST('mode_reglement_id'); $object->fk_account = GETPOST('fk_account', 'int'); - $object->contact_id = GETPOST('contactid', 'int'); + $object->contactid = GETPOST('contactid', 'int'); $object->fk_project = GETPOST('projectid', 'int'); - $object->model_pdf = GETPOST('model'); + $object->modelpdf = GETPOST('model'); $object->author = $user->id; // deprecated - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->note_public = GETPOST('note_public', 'restricthtml'); + $object->note_private = GETPOST('note_private', 'none'); + $object->note_public = GETPOST('note_public', 'none'); $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); @@ -540,15 +549,17 @@ setEventMessages($object->error, $object->errors, 'errors'); $error++; } - } // Standard creation - else { + } // Standard creation + else + { $id = $object->create($user); } if ($id > 0) { - // Insert default contacts if defined - if (GETPOST('contactid') > 0) { + // Insertion contact par defaut si defini + if (GETPOST('contactid') > 0) + { $result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external'); if ($result < 0) { @@ -582,7 +593,7 @@ $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - $model = $object->model_pdf; + $model = $object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -591,23 +602,29 @@ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); exit(); - } else { + } + else + { $db->rollback(); $action = 'create'; } - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); $action = 'create'; } } } - } // Classify billed + } + + // Classify billed elseif ($action == 'classifybilled' && $usercanclose) { $db->begin(); - $result = $object->cloture($user, $object::STATUS_BILLED, ''); + $result = $object->cloture($user, Propal::STATUS_BILLED, ''); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -617,21 +634,25 @@ if (!$error) { $db->commit(); - } else { + } + else + { $db->rollback(); } - } // Close proposal - elseif ($action == 'confirm_closeas' && $usercanclose && !GETPOST('cancel', 'alpha')) { + } + + // Close proposal + elseif ($action == 'setstatut' && $usercanclose && !GETPOST('cancel', 'alpha')) { if (!(GETPOST('statut', 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors'); - $action = 'closeas'; + $action = 'statut'; } else { // prevent browser refresh from closing proposal several times - if ($object->statut == $object::STATUS_VALIDATED) + if ($object->statut == Propal::STATUS_VALIDATED) { $db->begin(); - $result = $object->cloture($user, GETPOST('statut', 'int'), GETPOST('note_private', 'restricthtml')); + $result = $object->cloture($user, GETPOST('statut', 'int'), GETPOST('note_private', 'none')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -641,12 +662,16 @@ if (!$error) { $db->commit(); - } else { + } + else + { $db->rollback(); } } } - } // Reopen proposal + } + + // Reopen proposal elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) { // prevent browser refresh from reopening proposal several times if ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) @@ -663,88 +688,94 @@ if (!$error) { $db->commit(); - } else { + } + else + { $db->rollback(); } } - } // add lines from objectlinked + } + + // add lines from objectlinked elseif ($action == 'import_lines_from_object' - && $user->rights->propal->creer - && $object->statut == Propal::STATUS_DRAFT - ) - { - $fromElement = GETPOST('fromelement'); - $fromElementid = GETPOST('fromelementid'); - $importLines = GETPOST('line_checkbox'); - - if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) - { - if ($fromElement == 'commande') - { - dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php'); - $lineClassName = 'OrderLine'; - } elseif ($fromElement == 'propal') - { - dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php'); - $lineClassName = 'PropaleLigne'; - } - $nextRang = count($object->lines) + 1; - $importCount = 0; - $error = 0; - foreach ($importLines as $lineId) - { - $lineId = intval($lineId); - $originLine = new $lineClassName($db); - if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) - { - $originLine->fetch_optionals(); - $desc = $originLine->desc; - $pu_ht = $originLine->subprice; - $qty = $originLine->qty; - $txtva = $originLine->tva_tx; - $txlocaltax1 = $originLine->localtax1_tx; - $txlocaltax2 = $originLine->localtax2_tx; - $fk_product = $originLine->fk_product; - $remise_percent = $originLine->remise_percent; - $date_start = $originLine->date_start; - $date_end = $originLine->date_end; - $ventil = 0; - $info_bits = $originLine->info_bits; - $fk_remise_except = $originLine->fk_remise_except; - $price_base_type = 'HT'; - $pu_ttc = 0; - $type = $originLine->product_type; - $rang = $nextRang++; - $special_code = $originLine->special_code; - $origin = $originLine->element; - $origin_id = $originLine->id; - $fk_parent_line = 0; - $fk_fournprice = $originLine->fk_fournprice; - $pa_ht = $originLine->pa_ht; - $label = $originLine->label; - $array_options = $originLine->array_options; - $situation_percent = 100; - $fk_prev_id = ''; - $fk_unit = $originLine->fk_unit; - $pu_ht_devise = $originLine->multicurrency_subprice; - - $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $date_start, $date_end, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise, $fk_remise_except); - - if ($res > 0) { - $importCount++; - } else { - $error++; - } - } else { - $error++; - } - } - - if ($error) - { - setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors'); - } - } + && $user->rights->propal->creer + && $object->statut == Propal::STATUS_DRAFT + ) + { + $fromElement = GETPOST('fromelement'); + $fromElementid = GETPOST('fromelementid'); + $importLines = GETPOST('line_checkbox'); + + if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) + { + if ($fromElement == 'commande') + { + dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php'); + $lineClassName = 'OrderLine'; + } + elseif ($fromElement == 'propal') + { + dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php'); + $lineClassName = 'PropaleLigne'; + } + $nextRang = count($object->lines) + 1; + $importCount = 0; + $error = 0; + foreach ($importLines as $lineId) + { + $lineId = intval($lineId); + $originLine = new $lineClassName($db); + if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) + { + $originLine->fetch_optionals(); + $desc = $originLine->desc; + $pu_ht = $originLine->subprice; + $qty = $originLine->qty; + $txtva = $originLine->tva_tx; + $txlocaltax1 = $originLine->localtax1_tx; + $txlocaltax2 = $originLine->localtax2_tx; + $fk_product = $originLine->fk_product; + $remise_percent = $originLine->remise_percent; + $date_start = $originLine->date_start; + $date_end = $originLine->date_end; + $ventil = 0; + $info_bits = $originLine->info_bits; + $fk_remise_except = $originLine->fk_remise_except; + $price_base_type = 'HT'; + $pu_ttc = 0; + $type = $originLine->product_type; + $rang = $nextRang++; + $special_code = $originLine->special_code; + $origin = $originLine->element; + $origin_id = $originLine->id; + $fk_parent_line = 0; + $fk_fournprice = $originLine->fk_fournprice; + $pa_ht = $originLine->pa_ht; + $label = $originLine->label; + $array_options = $originLine->array_options; + $situation_percent = 100; + $fk_prev_id = ''; + $fk_unit = $originLine->fk_unit; + $pu_ht_devise = $originLine->multicurrency_subprice; + + $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $date_start, $date_end, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise, $fk_remise_except); + + if ($res > 0) { + $importCount++; + } else { + $error++; + } + } + else { + $error++; + } + } + + if ($error) + { + setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors'); + } + } } include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; @@ -772,10 +803,11 @@ $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records - if ($ret > 0) $object->fetch_thirdparty(); - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } elseif ($action == "setabsolutediscount" && $usercancreate) { + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + elseif ($action == "setabsolutediscount" && $usercancreate) { if ($_POST["remise_id"]) { if ($object->id > 0) { $result = $object->insert_discount($_POST["remise_id"]); @@ -784,32 +816,28 @@ } } } - } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('vatforalllines', 'alpha') !== '') { - // Define vat_rate - $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0); - $vat_rate = str_replace('*', '', $vat_rate); - $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); - $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); - foreach ($object->lines as $line) { - $result = $object->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); - } - } elseif ($action == 'addline' && $usercancreate) { // Add line + } + + // Add line + elseif ($action == 'addline' && $usercancreate) { // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); - $price_ht = price2num(GETPOST('price_ht'), 'MU', 2); - $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2); + $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $price_ht = GETPOST('price_ht'); + $price_ht_devise = GETPOST('multicurrency_price_ht'); $prod_entry_mode = GETPOST('prod_entry_mode'); if ($prod_entry_mode == 'free') { $idprod = 0; $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); - } else { + } + else + { $idprod = GETPOST('idprod', 'int'); $tva_tx = ''; } - $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS'); + $qty = GETPOST('qty'.$predef); $remise_percent = GETPOST('remise_percent'.$predef); if (empty($remise_percent)) $remise_percent = 0; @@ -829,7 +857,7 @@ $error++; } - if ($prod_entry_mode == 'free' && empty($idprod) && $price_ht === '' && $price_ht_devise === '') // Unit price can be 0 but not ''. Also price can be negative for proposal. + if ($prod_entry_mode == 'free' && empty($idprod) && $price_ht == '' && $price_ht_devise == '') // Unit price can be 0 but not ''. Also price can be negative for proposal. { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors'); $error++; @@ -893,10 +921,11 @@ $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility { - if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level]; - if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level]; - } - } // If price per customer + if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level]; + if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level]; + } + } + // If price per customer elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php'; @@ -911,7 +940,6 @@ if (count($prodcustprice->lines) > 0) { $pu_ht = price($prodcustprice->lines[0]->price); $pu_ttc = price($prodcustprice->lines[0]->price_ttc); - $price_min = price($prodcustprice->lines[0]->price_min); $price_base_type = $prodcustprice->lines[0]->price_base_type; $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx); if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; @@ -919,7 +947,8 @@ if (empty($tva_tx)) $tva_npr = 0; } } - } // If price per quantity + } + // If price per quantity elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { if ($prod->prices_by_qty[0]) // yes, this product has some prices per quantity @@ -935,14 +964,17 @@ if ($priceforthequantityarray['price_base_type'] == 'HT') { $pu_ht = $priceforthequantityarray['unitprice']; - } else { + } + else + { $pu_ttc = $priceforthequantityarray['unitprice']; } // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST. break; } } - } // If price per quantity and customer + } + // If price per quantity and customer elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { if ($prod->prices_by_qty[$object->thirdparty->price_level]) // yes, this product has some prices per quantity @@ -958,7 +990,9 @@ if ($priceforthequantityarray['price_base_type'] == 'HT') { $pu_ht = $priceforthequantityarray['unitprice']; - } else { + } + else + { $pu_ttc = $priceforthequantityarray['unitprice']; } // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST. @@ -971,10 +1005,11 @@ $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); // if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ? - if (!empty($price_ht) || $price_ht === '0') { + if (!empty($price_ht)) { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); - } // On reevalue prix selon taux tva car taux tva transaction peut etre different + } + // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). elseif ($tmpvat != $tmpprodvat) { if ($price_base_type != 'HT') { @@ -1106,7 +1141,7 @@ if ($ret > 0) { $object->fetch_thirdparty(); } - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } unset($_POST['prod_entry_mode']); @@ -1148,30 +1183,31 @@ } } } - } // Update a line within proposal + } + + // Update a line within proposal elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) { // Define info_bits $info_bits = 0; - if (preg_match('/\*/', GETPOST('tva_tx'))) { + if (preg_match('/\*/', GETPOST('tva_tx'))) $info_bits |= 0x01; - } - - // Clean parameters - $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml')); + + // Clean parameters + $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'none')); // Define vat_rate $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); $vat_rate = str_replace('*', '', $vat_rate); $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); - $pu_ht = price2num(GETPOST('price_ht'), '', 2); + $pu_ht = GETPOST('price_ht'); // Add buying price $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : ''); $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value - $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2); + $pu_ht_devise = GETPOST('multicurrency_subprice'); $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); @@ -1234,10 +1270,7 @@ } } } - - $qty = price2num(GETPOST('qty', 'alpha'), 'MS'); - - $result = $object->updateline(GETPOST('lineid', 'int'), $pu_ht, $qty, GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, $_POST["units"], $pu_ht_devise); + $result = $object->updateline(GETPOST('lineid'), $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, $_POST["units"], $pu_ht_devise); if ($result >= 0) { $db->commit(); @@ -1251,8 +1284,7 @@ $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records - if ($ret > 0) $object->fetch_thirdparty(); - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } unset($_POST['qty']); @@ -1290,46 +1322,70 @@ } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha')) { header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition exit(); - } elseif ($action == 'classin' && $usercancreate) { - // Set project - $object->setProject(GETPOST('projectid', 'int')); - } // Delivery time + } + + elseif ($action == 'classin' && $usercancreate) { + // Set project + $object->setProject(GETPOST('projectid', 'int')); + } + + // Delivery time elseif ($action == 'setavailability' && $usercancreate) { $result = $object->set_availability($user, GETPOST('availability_id', 'int')); - } // Origin of the commercial proposal + } + + // Origin of the commercial proposal elseif ($action == 'setdemandreason' && $usercancreate) { $result = $object->set_demand_reason($user, GETPOST('demand_reason_id', 'int')); - } // Terms of payment + } + + // Terms of payment elseif ($action == 'setconditions' && $usercancreate) { $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - } elseif ($action == 'setremisepercent' && $usercancreate) { + } + + elseif ($action == 'setremisepercent' && $usercancreate) { $result = $object->set_remise_percent($user, $_POST['remise_percent']); - } elseif ($action == 'setremiseabsolue' && $usercancreate) { + } + + elseif ($action == 'setremiseabsolue' && $usercancreate) { $result = $object->set_remise_absolue($user, $_POST['remise_absolue']); - } // Payment choice + } + + // Payment choice elseif ($action == 'setmode' && $usercancreate) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - } // Multicurrency Code + } + + // Multicurrency Code elseif ($action == 'setmulticurrencycode' && $usercancreate) { $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); - } // Multicurrency rate + } + + // Multicurrency rate elseif ($action == 'setmulticurrencyrate' && $usercancreate) { - $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int')); - } // bank account + $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx'))); + } + + // bank account elseif ($action == 'setbankaccount' && $usercancreate) { $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - } // shipping method + } + + // shipping method elseif ($action == 'setshippingmethod' && $usercancreate) { $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); - } elseif ($action == 'update_extras') { + } + + elseif ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (!$error) { - $result = $object->updateExtraField(GETPOST('attribute', 'restricthtml'), 'PROPAL_MODIFY', $user); + $result = $object->insertExtraFields('PROPAL_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -1345,8 +1401,7 @@ { if ($object->id > 0) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); } if ($result >= 0) { @@ -1360,14 +1415,18 @@ setEventMessages($object->error, $object->errors, 'errors'); } } - } // Toggle the status of a contact + } + + // Toggle the status of a contact elseif ($action == 'swapstatut') { if ($object->fetch($id) > 0) { $result = $object->swapContactStatus(GETPOST('ligne')); } else { dol_print_error($db); } - } // Delete a contact + } + + // Delete a contact elseif ($action == 'deletecontact') { $object->fetch($id); $result = $object->delete_contact($lineid); @@ -1477,7 +1536,9 @@ if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx; } } - } else { + } + else + { if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code; } @@ -1493,7 +1554,7 @@ print ''; } - print dol_get_fiche_head(); + dol_fiche_head(); print ''; @@ -1513,16 +1574,18 @@ print $soc->getNomUrl(1); print ''; print ''; + if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) { + $shipping_method_id = $soc->shipping_method_id; + } } else { print '
'; - print img_picto('', 'company').$form->select_company('', 'socid', '(s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500'); + print $form->select_company('', 'socid', '(s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); // reload page to retrieve customer informations - if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) + if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE)) { print '