';
print '| ';
print $langs->trans('IncotermLabel');
print ' | | ';
- if ($usercancreate) print ''.img_edit().'';
- else print ' ';
+ if ($usercancreate) {
+ print ''.img_edit().'';
+ } else {
+ print ' ';
+ }
print ' | ';
print ' | ';
- print '';
- if ($action != 'editincoterm')
- {
+ print ' | ';
+ if ($action != 'editincoterm') {
print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
} else {
print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
@@ -2321,8 +2351,7 @@ if ($action == 'create')
print '';
- if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
- {
+ if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
// Multicurrency Amount HT
print '| '.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).' | ';
print ''.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).' | ';
@@ -2350,14 +2379,12 @@ if ($action == 'create')
print ' ';
// Amount Local Taxes
- if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1
- {
+ if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1
print '| '.$langs->transcountry("AmountLT1", $mysoc->country_code).' | ';
print ''.price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency).' | ';
print ' ';
}
- if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2
- {
+ if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2
print '| '.$langs->transcountry("AmountLT2", $mysoc->country_code).' | ';
print ''.price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency).' | ';
print ' ';
@@ -2374,8 +2401,7 @@ if ($action == 'create')
print ' ';
// Margin Infos
- if (!empty($conf->margin->enabled))
- {
+ if (!empty($conf->margin->enabled)) {
$formmargin->displayMarginInfos($object);
}
@@ -2416,19 +2442,16 @@ if ($action == 'create')
}
print '';
- if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline'))
- {
+ if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) {
print ' ';
}
- if (!empty($object->lines))
- {
+ if (!empty($object->lines)) {
$ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
}
// Form to add new line
- if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines')
- {
+ if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines') {
if ($action != 'editline') {
// Add products/services form
$object->formAddObjectLine(1, $mysoc, $soc);
@@ -2441,8 +2464,7 @@ if ($action == 'create')
}
}
- if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline'))
- {
+ if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) {
print ' ';
}
print ' ';
@@ -2462,18 +2484,16 @@ if ($action == 'create')
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
// modified by hook
- if (empty($reshook))
- {
- if ($action != 'editline')
- {
+ if (empty($reshook)) {
+ if ($action != 'editline') {
// Validate
if (($object->statut == Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
- || ($object->statut == Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0))
- {
- if ($usercanvalidate)
- {
+ || ($object->statut == Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0)) {
+ if ($usercanvalidate) {
print 'id.'&action=validate">'.$langs->trans('Validate').'';
- } else print ''.$langs->trans('Validate').'';
+ } else {
+ print ''.$langs->trans('Validate').'';
+ }
}
// Create event
/*if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page.
@@ -2496,7 +2516,9 @@ if ($action == 'create')
if ($object->statut == Propal::STATUS_VALIDATED || $object->statut == Propal::STATUS_SIGNED || !empty($conf->global->PROPOSAL_SENDBYEMAIL_FOR_ALL_STATUS)) {
if ($usercansend) {
print 'id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'';
- } else print ''.$langs->trans('SendMail').'';
+ } else {
+ print ''.$langs->trans('SendMail').'';
+ }
}
}
@@ -2508,8 +2530,7 @@ if ($action == 'create')
}
// Create a purchase order
- if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL))
- {
+ if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL)) {
if (!empty($conf->fournisseur->enabled) && $object->statut == Propal::STATUS_SIGNED) {
if ($usercancreatepurchaseorder) {
print ''.$langs->trans("AddPurchaseOrder").'';
@@ -2535,18 +2556,14 @@ if ($action == 'create')
}
// Create an invoice and classify billed
- if ($object->statut == Propal::STATUS_SIGNED)
- {
- if (!empty($conf->facture->enabled) && $usercancreateinvoice)
- {
+ if ($object->statut == Propal::STATUS_SIGNED) {
+ if (!empty($conf->facture->enabled) && $usercancreateinvoice) {
print ''.$langs->trans("AddBill").'';
}
$arrayofinvoiceforpropal = $object->getInvoiceArrayList();
- if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED))
- {
- if ($usercanclose)
- {
+ if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED)) {
+ if ($usercanclose) {
print 'id.'&action=classifybilled&socid='.$object->socid.'">'.$langs->trans("ClassifyBilled").'';
} else {
print ''.$langs->trans("ClassifyBilled").'';
@@ -2577,14 +2594,15 @@ if ($action == 'create')
}
//Select mail models is same action as presend
- if (GETPOST('modelselected')) $action = 'presend';
+ if (GETPOST('modelselected')) {
+ $action = 'presend';
+ }
- if ($action != 'presend')
- {
+ if ($action != 'presend') {
print '';
print ' '; // ancre
/*
- * Documents generes
+ * Generated documents
*/
$objref = dol_sanitizeFileName($object->ref);
$filedir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
@@ -2598,8 +2616,7 @@ if ($action == 'create')
$linktoelem = $form->showLinkToObjectBlock($object, null, array('propal'));
$compatibleImportElementsList = false;
- if ($user->rights->propal->creer && $object->statut == Propal::STATUS_DRAFT)
- {
+ if ($user->rights->propal->creer && $object->statut == Propal::STATUS_DRAFT) {
$compatibleImportElementsList = array('commande', 'propal'); // import from linked elements
}
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
@@ -2607,16 +2624,14 @@ if ($action == 'create')
// Show online signature link
$useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok
- if ($object->statut != Propal::STATUS_DRAFT && $useonlinesignature)
- {
+ if ($object->statut != Propal::STATUS_DRAFT && $useonlinesignature) {
print ' ';
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
print showOnlineSignatureUrl('proposal', $object->ref).' ';
}
// Show direct download link
- if ($object->statut != Propal::STATUS_DRAFT && !empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD))
- {
+ if ($object->statut != Propal::STATUS_DRAFT && !empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
print ' '."\n";
print showDirectDownloadLink($object).' ';
}
diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php
index fd2cb3d371c..84d7cf23385 100644
--- a/htdocs/comm/propal/class/api_proposals.class.php
+++ b/htdocs/comm/propal/class/api_proposals.class.php
@@ -162,28 +162,37 @@ class Proposals extends DolibarrApi
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
- if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
+ if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
+ $search_sale = DolibarrApiAccess::$user->id;
+ }
$sql = "SELECT t.rowid";
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
+ $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
+ }
$sql .= " FROM ".MAIN_DB_PREFIX."propal as t";
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
+ }
$sql .= ' WHERE t.entity IN ('.getEntity('propal').')';
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
- if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
- if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
+ $sql .= " AND t.fk_soc = sc.fk_soc";
+ }
+ if ($socids) {
+ $sql .= " AND t.fk_soc IN (".$socids.")";
+ }
+ if ($search_sale > 0) {
+ $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
+ }
// Insert sale filter
- if ($search_sale > 0)
- {
+ if ($search_sale > 0) {
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Add sql filters
- if ($sqlfilters)
- {
- if (!DolibarrApi::_checkFilters($sqlfilters))
- {
+ if ($sqlfilters) {
+ if (!DolibarrApi::_checkFilters($sqlfilters)) {
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@@ -192,8 +201,7 @@ class Proposals extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
- if ($page < 0)
- {
+ if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
@@ -204,13 +212,11 @@ class Proposals extends DolibarrApi
dol_syslog("API Rest request");
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0;
- while ($i < $min)
- {
+ while ($i < $min) {
$obj = $this->db->fetch_object($result);
$proposal_static = new Propal($this->db);
if ($proposal_static->fetch($obj->rowid)) {
@@ -247,12 +253,12 @@ class Proposals extends DolibarrApi
$this->propal->$field = $value;
}
/*if (isset($request_data["lines"])) {
- $lines = array();
- foreach ($request_data["lines"] as $line) {
- array_push($lines, (object) $line);
- }
- $this->propal->lines = $lines;
- }*/
+ $lines = array();
+ foreach ($request_data["lines"] as $line) {
+ array_push($lines, (object) $line);
+ }
+ $this->propal->lines = $lines;
+ }*/
if ($this->propal->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating order", array_merge(array($this->propal->error), $this->propal->errors));
}
@@ -304,7 +310,7 @@ class Proposals extends DolibarrApi
public function postLine($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->rights->propal->creer) {
- throw new RestException(401);
+ throw new RestException(401);
}
$result = $this->propal->fetch($id);
@@ -319,32 +325,32 @@ class Proposals extends DolibarrApi
$request_data = (object) $request_data;
$updateRes = $this->propal->addline(
- $request_data->desc,
- $request_data->subprice,
- $request_data->qty,
- $request_data->tva_tx,
- $request_data->localtax1_tx,
- $request_data->localtax2_tx,
- $request_data->fk_product,
- $request_data->remise_percent,
- 'HT',
- 0,
- $request_data->info_bits,
- $request_data->product_type,
- $request_data->rang,
- $request_data->special_code,
- $request_data->fk_parent_line,
- $request_data->fk_fournprice,
- $request_data->pa_ht,
- $request_data->label,
- $request_data->date_start,
- $request_data->date_end,
- $request_data->array_options,
- $request_data->fk_unit,
- $request_data->origin,
- $request_data->origin_id,
- $request_data->multicurrency_subprice,
- $request_data->fk_remise_except
+ $request_data->desc,
+ $request_data->subprice,
+ $request_data->qty,
+ $request_data->tva_tx,
+ $request_data->localtax1_tx,
+ $request_data->localtax2_tx,
+ $request_data->fk_product,
+ $request_data->remise_percent,
+ 'HT',
+ 0,
+ $request_data->info_bits,
+ $request_data->product_type,
+ $request_data->rang,
+ $request_data->special_code,
+ $request_data->fk_parent_line,
+ $request_data->fk_fournprice,
+ $request_data->pa_ht,
+ $request_data->label,
+ $request_data->date_start,
+ $request_data->date_end,
+ $request_data->array_options,
+ $request_data->fk_unit,
+ $request_data->origin,
+ $request_data->origin_id,
+ $request_data->multicurrency_subprice,
+ $request_data->fk_remise_except
);
if ($updateRes > 0) {
@@ -378,15 +384,15 @@ class Proposals extends DolibarrApi
if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ }
- $request_data = (object) $request_data;
+ $request_data = (object) $request_data;
- $propalline = new PropaleLigne($this->db);
- $result = $propalline->fetch($lineid);
- if ($result <= 0) {
- throw new RestException(404, 'Proposal line not found');
- }
+ $propalline = new PropaleLigne($this->db);
+ $result = $propalline->fetch($lineid);
+ if ($result <= 0) {
+ throw new RestException(404, 'Proposal line not found');
+ }
$updateRes = $this->propal->updateline(
$lineid,
@@ -572,25 +578,23 @@ class Proposals extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
foreach ($request_data as $field => $value) {
- if ($field == 'id') continue;
+ if ($field == 'id') {
+ continue;
+ }
$this->propal->$field = $value;
}
// update end of validity date
- if (empty($this->propal->fin_validite) && !empty($this->propal->duree_validite) && !empty($this->propal->date_creation))
- {
+ if (empty($this->propal->fin_validite) && !empty($this->propal->duree_validite) && !empty($this->propal->date_creation)) {
$this->propal->fin_validite = $this->propal->date_creation + ($this->propal->duree_validite * 24 * 3600);
}
- if (!empty($this->propal->fin_validite))
- {
- if ($this->propal->set_echeance(DolibarrApiAccess::$user, $this->propal->fin_validite) < 0)
- {
+ if (!empty($this->propal->fin_validite)) {
+ if ($this->propal->set_echeance(DolibarrApiAccess::$user, $this->propal->fin_validite) < 0) {
throw new RestException(500, $this->propal->error);
}
}
- if ($this->propal->update(DolibarrApiAccess::$user) > 0)
- {
+ if ($this->propal->update(DolibarrApiAccess::$user) > 0) {
return $this->get($id);
} else {
throw new RestException(500, $this->propal->error);
@@ -834,8 +838,9 @@ class Proposals extends DolibarrApi
{
$propal = array();
foreach (Proposals::$FIELDS as $field) {
- if (!isset($data[$field]))
+ if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
+ }
$propal[$field] = $data[$field];
}
return $propal;
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index a115d8bca5e..197c9c7074f 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -13,7 +13,7 @@
* Copyright (C) 2013 Florian Henry
* Copyright (C) 2014-2015 Marcos García
* Copyright (C) 2018 Nicolas ZABOURI
- * Copyright (C) 2018-2020 Frédéric France
+ * Copyright (C) 2018-2021 Frédéric France
* Copyright (C) 2018 Ferran Marcet
*
* This program is free software; you can redistribute it and/or modify
@@ -285,10 +285,10 @@ class Propal extends CommonObject
'remise_absolue' =>array('type'=>'double', 'label'=>'CustomerRelativeDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>115),
//'remise' =>array('type'=>'double', 'label'=>'Remise', 'enabled'=>1, 'visible'=>-1, 'position'=>120),
'total_ht' =>array('type'=>'double(24,8)', 'label'=>'TotalHT', 'enabled'=>1, 'visible'=>-1, 'position'=>125, 'isameasure'=>1),
- 'tva' =>array('type'=>'double(24,8)', 'label'=>'VAT', 'enabled'=>1, 'visible'=>-1, 'position'=>130, 'isameasure'=>1),
+ 'total_tva' =>array('type'=>'double(24,8)', 'label'=>'VAT', 'enabled'=>1, 'visible'=>-1, 'position'=>130, 'isameasure'=>1),
'localtax1' =>array('type'=>'double(24,8)', 'label'=>'LocalTax1', 'enabled'=>1, 'visible'=>-1, 'position'=>135, 'isameasure'=>1),
'localtax2' =>array('type'=>'double(24,8)', 'label'=>'LocalTax2', 'enabled'=>1, 'visible'=>-1, 'position'=>140, 'isameasure'=>1),
- 'total' =>array('type'=>'double(24,8)', 'label'=>'TotalTTC', 'enabled'=>1, 'visible'=>-1, 'position'=>145, 'isameasure'=>1),
+ 'total_ttc' =>array('type'=>'double(24,8)', 'label'=>'TotalTTC', 'enabled'=>1, 'visible'=>-1, 'position'=>145, 'isameasure'=>1),
'fk_account' =>array('type'=>'integer', 'label'=>'BankAccount', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
'fk_currency' =>array('type'=>'varchar(3)', 'label'=>'Currency', 'enabled'=>1, 'visible'=>-1, 'position'=>155),
'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'PaymentTerm', 'enabled'=>1, 'visible'=>-1, 'position'=>160),
@@ -376,11 +376,12 @@ class Propal extends CommonObject
// phpcs:enable
global $conf, $mysoc;
- if (!$qty) $qty = 1;
+ if (!$qty) {
+ $qty = 1;
+ }
dol_syslog(get_class($this)."::add_product $idproduct, $qty, $remise_percent");
- if ($idproduct > 0)
- {
+ if ($idproduct > 0) {
$prod = new Product($this->db);
$prod->fetch($idproduct);
@@ -388,15 +389,16 @@ class Propal extends CommonObject
$tva_tx = get_default_tva($mysoc, $this->thirdparty, $prod->id);
$tva_npr = get_default_npr($mysoc, $this->thirdparty, $prod->id);
- if (empty($tva_tx)) $tva_npr = 0;
+ if (empty($tva_tx)) {
+ $tva_npr = 0;
+ }
$vat_src_code = ''; // May be defined into tva_tx
$localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr);
$localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr);
// multiprices
- if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level)
- {
+ if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) {
$price = $prod->multiprices[$this->thirdparty->price_level];
} else {
$price = $prod->price;
@@ -412,7 +414,9 @@ class Propal extends CommonObject
$line->vat_src_code = $vat_src_code;
$line->tva_tx = $tva_tx;
$line->fk_unit = $prod->fk_unit;
- if ($tva_npr) $line->info_bits = 1;
+ if ($tva_npr) {
+ $line->info_bits = 1;
+ }
$this->lines[] = $line;
}
@@ -438,10 +442,8 @@ class Propal extends CommonObject
$remise = new DiscountAbsolute($this->db);
$result = $remise->fetch($idremise);
- if ($result > 0)
- {
- if ($remise->fk_facture) // Protection against multiple submission
- {
+ if ($result > 0) {
+ if ($remise->fk_facture) { // Protection against multiple submission
$this->error = $langs->trans("ErrorDiscountAlreadyUsed");
$this->db->rollback();
return -5;
@@ -472,11 +474,9 @@ class Propal extends CommonObject
$line->total_ttc = -$remise->amount_ttc;
$result = $line->insert();
- if ($result > 0)
- {
+ if ($result > 0) {
$result = $this->update_price(1);
- if ($result > 0)
- {
+ if ($result > 0) {
$this->db->commit();
return 1;
} else {
@@ -537,16 +537,25 @@ class Propal extends CommonObject
dol_syslog(get_class($this)."::addline propalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type, fk_remise_except=".$fk_remise_except);
- if ($this->statut == self::STATUS_DRAFT)
- {
+ if ($this->statut == self::STATUS_DRAFT) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters
- if (empty($remise_percent)) $remise_percent = 0;
- if (empty($qty)) $qty = 0;
- if (empty($info_bits)) $info_bits = 0;
- if (empty($rang)) $rang = 0;
- if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line = 0;
+ if (empty($remise_percent)) {
+ $remise_percent = 0;
+ }
+ if (empty($qty)) {
+ $qty = 0;
+ }
+ if (empty($info_bits)) {
+ $info_bits = 0;
+ }
+ if (empty($rang)) {
+ $rang = 0;
+ }
+ if (empty($fk_parent_line) || $fk_parent_line < 0) {
+ $fk_parent_line = 0;
+ }
$remise_percent = price2num($remise_percent);
$qty = price2num($qty);
@@ -559,15 +568,16 @@ class Propal extends CommonObject
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
$pa_ht = price2num($pa_ht);
- if ($price_base_type == 'HT')
- {
+ if ($price_base_type == 'HT') {
$pu = $pu_ht;
} else {
$pu = $pu_ttc;
}
// Check parameters
- if ($type < 0) return -1;
+ if ($type < 0) {
+ return -1;
+ }
if ($date_start && $date_end && $date_start > $date_end) {
$langs->load("errors");
@@ -578,8 +588,7 @@ class Propal extends CommonObject
$this->db->begin();
$product_type = $type;
- if (!empty($fk_product))
- {
+ if (!empty($fk_product)) {
$product = new Product($this->db);
$result = $product->fetch($fk_product);
$product_type = $product->type;
@@ -603,8 +612,7 @@ class Propal extends CommonObject
$reg = array();
$vat_src_code = '';
$reg = array();
- if (preg_match('/\((.*)\)/', $txtva, $reg))
- {
+ if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
@@ -628,8 +636,7 @@ class Propal extends CommonObject
// Rang to use
$ranktouse = $rang;
- if ($ranktouse == -1)
- {
+ if ($ranktouse == -1) {
$rangmax = $this->line_max($fk_parent_line);
$ranktouse = $rangmax + 1;
}
@@ -638,8 +645,7 @@ class Propal extends CommonObject
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
$price = $pu;
$remise = 0;
- if ($remise_percent > 0)
- {
+ if ($remise_percent > 0) {
$remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise;
}
@@ -694,7 +700,9 @@ class Propal extends CommonObject
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
// Mise en option de la ligne
- if (empty($qty) && empty($special_code)) $this->line->special_code = 3;
+ if (empty($qty) && empty($special_code)) {
+ $this->line->special_code = 3;
+ }
// TODO deprecated
$this->line->price = $price;
@@ -705,10 +713,11 @@ class Propal extends CommonObject
}
$result = $this->line->insert();
- if ($result > 0)
- {
+ if ($result > 0) {
// Reorder if child line
- if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
+ if (!empty($fk_parent_line)) {
+ $this->line_order(true, 'DESC');
+ }
// Mise a jour informations denormalisees au niveau de la propale meme
$result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode.
@@ -781,9 +790,15 @@ class Propal extends CommonObject
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
$pa_ht = price2num($pa_ht);
- if (empty($qty) && empty($special_code)) $special_code = 3; // Set option tag
- if (!empty($qty) && $special_code == 3) $special_code = 0; // Remove option tag
- if (empty($type)) $type = 0;
+ if (empty($qty) && empty($special_code)) {
+ $special_code = 3; // Set option tag
+ }
+ if (!empty($qty) && $special_code == 3) {
+ $special_code = 0; // Remove option tag
+ }
+ if (empty($type)) {
+ $type = 0;
+ }
if ($date_start && $date_end && $date_start > $date_end) {
$langs->load("errors");
@@ -791,8 +806,7 @@ class Propal extends CommonObject
return -1;
}
- if ($this->statut == self::STATUS_DRAFT)
- {
+ if ($this->statut == self::STATUS_DRAFT) {
$this->db->begin();
// Calcul du total TTC et de la TVA pour la ligne a partir de
@@ -805,8 +819,7 @@ class Propal extends CommonObject
// Clean vat code
$reg = array();
$vat_src_code = '';
- if (preg_match('/\((.*)\)/', $txtva, $reg))
- {
+ if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
@@ -830,8 +843,7 @@ class Propal extends CommonObject
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
$price = $pu;
$remise = 0;
- if ($remise_percent > 0)
- {
+ if ($remise_percent > 0) {
$remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise;
}
@@ -847,8 +859,7 @@ class Propal extends CommonObject
$this->line->context = $this->context;
// Reorder if fk_parent_line change
- if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
- {
+ if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
$rangmax = $this->line_max($fk_parent_line);
$this->line->rang = $rangmax + 1;
}
@@ -902,10 +913,11 @@ class Propal extends CommonObject
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
$result = $this->line->update($notrigger);
- if ($result > 0)
- {
+ if ($result > 0) {
// Reorder if child line
- if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
+ if (!empty($fk_parent_line)) {
+ $this->line_order(true, 'DESC');
+ }
$this->update_price(1);
@@ -937,8 +949,7 @@ class Propal extends CommonObject
{
global $user;
- if ($this->statut == self::STATUS_DRAFT)
- {
+ if ($this->statut == self::STATUS_DRAFT) {
$this->db->begin();
$line = new PropaleLigne($this->db);
@@ -946,8 +957,7 @@ class Propal extends CommonObject
// For triggers
$line->fetch($lineid);
- if ($line->delete($user) > 0)
- {
+ if ($line->delete($user) > 0) {
$this->update_price(1);
$this->db->commit();
@@ -979,16 +989,24 @@ class Propal extends CommonObject
$now = dol_now();
// Clean parameters
- if (empty($this->date)) $this->date = $this->datep;
+ if (empty($this->date)) {
+ $this->date = $this->datep;
+ }
$this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
- if (empty($this->availability_id)) $this->availability_id = 0;
- if (empty($this->demand_reason_id)) $this->demand_reason_id = 0;
+ if (empty($this->availability_id)) {
+ $this->availability_id = 0;
+ }
+ if (empty($this->demand_reason_id)) {
+ $this->demand_reason_id = 0;
+ }
// Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate)
- if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date);
- else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
- if (empty($this->fk_multicurrency))
- {
+ if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
+ list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date);
+ } else {
+ $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
+ }
+ if (empty($this->fk_multicurrency)) {
$this->multicurrency_code = $conf->currency;
$this->fk_multicurrency = 0;
$this->multicurrency_tx = 1;
@@ -1001,19 +1019,16 @@ class Propal extends CommonObject
// Check parameters
$result = $this->fetch_thirdparty();
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = "Failed to fetch company";
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
return -3;
}
// Check parameters
- if (!empty($this->ref)) // We check that ref is not already used
- {
+ if (!empty($this->ref)) { // We check that ref is not already used
$result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
- if ($result > 0)
- {
+ if ($result > 0) {
$this->error = 'ErrorRefAlreadyExists';
dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
$this->db->rollback();
@@ -1021,8 +1036,7 @@ class Propal extends CommonObject
}
}
- if (empty($this->date))
- {
+ if (empty($this->date)) {
$this->error = "Date of proposal is required";
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
return -4;
@@ -1038,8 +1052,8 @@ class Propal extends CommonObject
$sql .= ", remise";
$sql .= ", remise_percent";
$sql .= ", remise_absolue";
- $sql .= ", tva";
- $sql .= ", total";
+ $sql .= ", total_tva";
+ $sql .= ", total_ttc";
$sql .= ", datep";
$sql .= ", datec";
$sql .= ", ref";
@@ -1101,36 +1115,30 @@ class Propal extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal");
- if ($this->id)
- {
+ if ($this->id) {
$this->ref = '(PROV'.$this->id.')';
$sql = 'UPDATE '.MAIN_DB_PREFIX."propal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".((int) $this->id);
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql) $error++;
+ if (!$resql) {
+ $error++;
+ }
- if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects
- {
+ if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
$this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
}
// Add object linked
- if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects))
- {
- foreach ($this->linked_objects as $origin => $tmp_origin_id)
- {
- if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
- {
- foreach ($tmp_origin_id as $origin_id)
- {
+ if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
+ foreach ($this->linked_objects as $origin => $tmp_origin_id) {
+ if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
+ foreach ($tmp_origin_id as $origin_id) {
$ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
+ if (!$ret) {
$this->error = $this->db->lasterror();
$error++;
}
@@ -1139,8 +1147,7 @@ class Propal extends CommonObject
{
$origin_id = $tmp_origin_id;
$ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
+ if (!$ret) {
$this->error = $this->db->lasterror();
$error++;
}
@@ -1149,18 +1156,16 @@ class Propal extends CommonObject
}
/*
- * Insertion du detail des produits dans la base
- * Insert products detail in database
- */
- if (!$error)
- {
+ * Insertion du detail des produits dans la base
+ * Insert products detail in database
+ */
+ if (!$error) {
$fk_parent_line = 0;
$num = count($this->lines);
- for ($i = 0; $i < $num; $i++)
- {
- if (!is_object($this->lines[$i])) // If this->lines is not array of objects, coming from REST API
- { // Convert into object this->lines[$i].
+ for ($i = 0; $i < $num; $i++) {
+ if (!is_object($this->lines[$i])) { // If this->lines is not array of objects, coming from REST API
+ // Convert into object this->lines[$i].
$line = (object) $this->lines[$i];
} else {
$line = $this->lines[$i];
@@ -1171,7 +1176,9 @@ class Propal extends CommonObject
}
// Complete vat rate with code
$vatrate = $line->tva_tx;
- if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')';
+ if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) {
+ $vatrate .= ' ('.$line->vat_src_code.')';
+ }
if (!empty($conf->global->MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION)) {
$originid = $line->origin_id;
@@ -1208,8 +1215,7 @@ class Propal extends CommonObject
$originid
);
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
$this->error = $this->db->error;
dol_print_error($this->db);
@@ -1233,29 +1239,26 @@ class Propal extends CommonObject
$result=$this->db->query($sql);
}*/
- if (!$error)
- {
+ if (!$error) {
// Mise a jour infos denormalisees
$resql = $this->update_price(1);
- if ($resql)
- {
+ if ($resql) {
$action = 'update';
// Actions on extra fields
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('PROPAL_CREATE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
} else {
@@ -1268,8 +1271,7 @@ class Propal extends CommonObject
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
dol_syslog(get_class($this)."::create done id=".$this->id);
return $this->id;
@@ -1313,25 +1315,23 @@ class Propal extends CommonObject
$objsoc = new Societe($this->db);
// Change socid if needed
- if (!empty($socid) && $socid != $object->socid)
- {
- if ($objsoc->fetch($socid) > 0)
- {
+ if (!empty($socid) && $socid != $object->socid) {
+ if ($objsoc->fetch($socid) > 0) {
$object->socid = $objsoc->id;
$object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
$object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
$object->fk_delivery_address = '';
/*if (!empty($conf->projet->enabled))
- {
- $project = new Project($db);
- if ($this->fk_project > 0 && $project->fetch($this->fk_project)) {
- if ($project->socid <= 0) $clonedObj->fk_project = $this->fk_project;
- else $clonedObj->fk_project = '';
- } else {
- $clonedObj->fk_project = '';
- }
- }*/
+ {
+ $project = new Project($db);
+ if ($this->fk_project > 0 && $project->fetch($this->fk_project)) {
+ if ($project->socid <= 0) $clonedObj->fk_project = $this->fk_project;
+ else $clonedObj->fk_project = '';
+ } else {
+ $clonedObj->fk_project = '';
+ }
+ }*/
$object->fk_project = ''; // A cloned proposal is set by default to no project.
}
@@ -1354,58 +1354,54 @@ class Propal extends CommonObject
$object->date = $now;
$object->datep = $now; // deprecated
$object->fin_validite = $object->date + ($object->duree_validite * 24 * 3600);
- if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $object->ref_client = '';
- if ($conf->global->MAIN_DONT_KEEP_NOTE_ON_CLONING == 1)
- {
+ if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) {
+ $object->ref_client = '';
+ }
+ if ($conf->global->MAIN_DONT_KEEP_NOTE_ON_CLONING == 1) {
$object->note_private = '';
$object->note_public = '';
}
// Create clone
$object->context['createfromclone'] = 'createfromclone';
$result = $object->create($user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $object->error;
$this->errors = array_merge($this->errors, $object->errors);
$error++;
}
- if (!$error)
- {
+ if (!$error) {
// copy internal contacts
- if ($object->copy_linked_contact($this, 'internal') < 0)
- {
+ if ($object->copy_linked_contact($this, 'internal') < 0) {
$error++;
}
}
- if (!$error)
- {
+ if (!$error) {
// copy external contacts if same company
- if ($this->socid == $object->socid)
- {
- if ($object->copy_linked_contact($this, 'external') < 0)
+ if ($this->socid == $object->socid) {
+ if ($object->copy_linked_contact($this, 'external') < 0) {
$error++;
+ }
}
}
- if (!$error)
- {
+ if (!$error) {
// Hook of thirdparty module
- if (is_object($hookmanager))
- {
+ if (is_object($hookmanager)) {
$parameters = array('objFrom'=>$this, 'clonedObj'=>$object);
$action = '';
$reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) $error++;
+ if ($reshook < 0) {
+ $error++;
+ }
}
}
unset($object->context['createfromclone']);
// End
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return $object->id;
} else {
@@ -1425,7 +1421,7 @@ class Propal extends CommonObject
public function fetch($rowid, $ref = '', $ref_ext = '')
{
$sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
- $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht";
+ $sql .= ", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
$sql .= ", p.datec";
$sql .= ", p.date_valid as datev";
$sql .= ", p.datep as dp";
@@ -1463,14 +1459,14 @@ class Propal extends CommonObject
if ($ref) {
$sql .= " WHERE p.entity IN (".getEntity('propal').")"; // Dont't use entity if you use rowid
$sql .= " AND p.ref='".$this->db->escape($ref)."'";
- } else $sql .= " WHERE p.rowid=".$rowid;
+ } else {
+ $sql .= " WHERE p.rowid=".$rowid;
+ }
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- if ($this->db->num_rows($resql))
- {
+ if ($resql) {
+ if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@@ -1481,12 +1477,12 @@ class Propal extends CommonObject
$this->remise = $obj->remise;
$this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue;
- $this->total = $obj->total; // TODO deprecated
+ $this->total = $obj->total_ttc; // TODO deprecated
+ $this->total_ttc = $obj->total_ttc;
$this->total_ht = $obj->total_ht;
- $this->total_tva = $obj->tva;
+ $this->total_tva = $obj->total_tva;
$this->total_localtax1 = $obj->localtax1;
$this->total_localtax2 = $obj->localtax2;
- $this->total_ttc = $obj->total;
$this->socid = $obj->fk_soc;
$this->thirdparty = null; // Clear if another value was already set by fetch_thirdparty
@@ -1537,8 +1533,8 @@ class Propal extends CommonObject
$this->extraparams = (array) json_decode($obj->extraparams, true);
$this->user_author_id = $obj->fk_user_author;
- $this->user_valid_id = $obj->fk_user_valid;
- $this->user_close_id = $obj->fk_user_cloture;
+ $this->user_valid_id = $obj->fk_user_valid;
+ $this->user_close_id = $obj->fk_user_cloture;
//Incoterms
$this->fk_incoterms = $obj->fk_incoterms;
@@ -1550,11 +1546,10 @@ class Propal extends CommonObject
$this->multicurrency_code = $obj->multicurrency_code;
$this->multicurrency_tx = $obj->multicurrency_tx;
$this->multicurrency_total_ht = $obj->multicurrency_total_ht;
- $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
- $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
+ $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
+ $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
- if ($obj->fk_statut == self::STATUS_DRAFT)
- {
+ if ($obj->fk_statut == self::STATUS_DRAFT) {
$this->brouillon = 1;
}
@@ -1568,8 +1563,7 @@ class Propal extends CommonObject
// Lines
$result = $this->fetch_lines();
- if ($result < 0)
- {
+ if ($result < 0) {
return -3;
}
@@ -1598,13 +1592,27 @@ class Propal extends CommonObject
$error = 0;
// Clean parameters
- if (isset($this->ref)) $this->ref = trim($this->ref);
- if (isset($this->ref_client)) $this->ref_client = trim($this->ref_client);
- if (isset($this->note) || isset($this->note_private)) $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
- if (isset($this->note_public)) $this->note_public = trim($this->note_public);
- if (isset($this->model_pdf)) $this->model_pdf = trim($this->model_pdf);
- if (isset($this->import_key)) $this->import_key = trim($this->import_key);
- if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
+ if (isset($this->ref)) {
+ $this->ref = trim($this->ref);
+ }
+ if (isset($this->ref_client)) {
+ $this->ref_client = trim($this->ref_client);
+ }
+ if (isset($this->note) || isset($this->note_private)) {
+ $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
+ }
+ if (isset($this->note_public)) {
+ $this->note_public = trim($this->note_public);
+ }
+ if (isset($this->model_pdf)) {
+ $this->model_pdf = trim($this->model_pdf);
+ }
+ if (isset($this->import_key)) {
+ $this->import_key = trim($this->import_key);
+ }
+ if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) {
+ $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
+ }
// Check parameters
// Put here code to add control on parameters values
@@ -1616,13 +1624,15 @@ class Propal extends CommonObject
$sql .= " ref_ext=".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").",";
$sql .= " fk_soc=".(isset($this->socid) ? $this->socid : "null").",";
$sql .= " datep=".(strval($this->date) != '' ? "'".$this->db->idate($this->date)."'" : 'null').",";
- if (!empty($this->fin_validite)) $sql .= " fin_validite=".(strval($this->fin_validite) != '' ? "'".$this->db->idate($this->fin_validite)."'" : 'null').",";
+ if (!empty($this->fin_validite)) {
+ $sql .= " fin_validite=".(strval($this->fin_validite) != '' ? "'".$this->db->idate($this->fin_validite)."'" : 'null').",";
+ }
$sql .= " date_valid=".(strval($this->date_validation) != '' ? "'".$this->db->idate($this->date_validation)."'" : 'null').",";
- $sql .= " tva=".(isset($this->total_tva) ? $this->total_tva : "null").",";
+ $sql .= " total_tva=".(isset($this->total_tva) ? $this->total_tva : "null").",";
$sql .= " localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 : "null").",";
$sql .= " localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 : "null").",";
$sql .= " total_ht=".(isset($this->total_ht) ? $this->total_ht : "null").",";
- $sql .= " total=".(isset($this->total_ttc) ? $this->total_ttc : "null").",";
+ $sql .= " total_ttc=".(isset($this->total_ttc) ? $this->total_ttc : "null").",";
$sql .= " fk_statut=".(isset($this->statut) ? $this->statut : "null").",";
$sql .= " fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id : "null").",";
$sql .= " fk_user_valid=".(isset($this->user_valid) ? $this->user_valid : "null").",";
@@ -1634,38 +1644,36 @@ class Propal extends CommonObject
$sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
$sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").",";
$sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null")."";
- $sql .= " WHERE rowid=".$this->id;
+ $sql .= " WHERE rowid=".((int) $this->id);
$this->db->begin();
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
- $error++; $this->errors[] = "Error ".$this->db->lasterror();
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
}
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
// Commit or rollback
- if ($error)
- {
- foreach ($this->errors as $errmsg)
- {
+ if ($error) {
+ foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -1703,20 +1711,20 @@ class Propal extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as d';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (d.fk_product = p.rowid)';
$sql .= ' WHERE d.fk_propal = '.$this->id;
- if ($only_product) $sql .= ' AND p.fk_product_type = 0';
+ if ($only_product) {
+ $sql .= ' AND p.fk_product_type = 0';
+ }
$sql .= ' ORDER by d.rang';
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$num = $this->db->num_rows($result);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$objp = $this->db->fetch_object($result);
$line = new PropaleLigne($this->db);
@@ -1824,15 +1832,13 @@ class Propal extends CommonObject
$error = 0;
// Protection
- if ($this->statut == self::STATUS_VALIDATED)
- {
+ if ($this->statut == self::STATUS_VALIDATED) {
dol_syslog(get_class($this)."::valid action abandonned: already validated", LOG_WARNING);
return 0;
}
if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->creer))
- || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate))))
- {
+ || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)))) {
$this->error = 'ErrorPermissionDenied';
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1;
@@ -1847,8 +1853,7 @@ class Propal extends CommonObject
$soc->fetch($this->socid);
// Define new ref
- if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
- {
+ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
$num = $this->getNextNumRef($soc);
} else {
$num = $this->ref;
@@ -1862,49 +1867,47 @@ class Propal extends CommonObject
dol_syslog(get_class($this)."::valid", LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
dol_print_error($this->db);
$error++;
}
// Trigger calls
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('PROPAL_VALIDATE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->oldref = $this->ref;
// Rename directory if dir was a temporary ref
- if (preg_match('/^[\(]?PROV/i', $this->ref))
- {
+ if (preg_match('/^[\(]?PROV/i', $this->ref)) {
// Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'propale/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'propale/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$resql = $this->db->query($sql);
- if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
+ if (!$resql) {
+ $error++;
+ $this->error = $this->db->lasterror();
+ }
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
$oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($num);
$dirsource = $conf->propal->multidir_output[$this->entity].'/'.$oldref;
$dirdest = $conf->propal->multidir_output[$this->entity].'/'.$newref;
- if (!$error && file_exists($dirsource))
- {
+ if (!$error && file_exists($dirsource)) {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
- if (@rename($dirsource, $dirdest))
- {
+ if (@rename($dirsource, $dirdest)) {
dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
$listoffiles = dol_dir_list($dirdest, 'files', 1, '^'.preg_quote($oldref, '/'));
- foreach ($listoffiles as $fileentry)
- {
+ foreach ($listoffiles as $fileentry) {
$dirsource = $fileentry['name'];
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$dirsource = $fileentry['path'].'/'.$dirsource;
@@ -1942,15 +1945,13 @@ class Propal extends CommonObject
public function set_date($user, $date, $notrigger = 0)
{
// phpcs:enable
- if (empty($date))
- {
+ if (empty($date)) {
$this->error = 'ErrorBadParameter';
dol_syslog(get_class($this)."::set_date ".$this->error, LOG_ERR);
return -1;
}
- if (!empty($user->rights->propal->creer))
- {
+ if (!empty($user->rights->propal->creer)) {
$error = 0;
$this->db->begin();
@@ -1960,34 +1961,31 @@ class Propal extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->date = $date;
$this->datep = $date; // deprecated
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2009,8 +2007,7 @@ class Propal extends CommonObject
public function set_echeance($user, $date_fin_validite, $notrigger = 0)
{
// phpcs:enable
- if (!empty($user->rights->propal->creer))
- {
+ if (!empty($user->rights->propal->creer)) {
$error = 0;
$this->db->begin();
@@ -2020,34 +2017,31 @@ class Propal extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->fin_validite = $date_fin_validite;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2083,8 +2077,7 @@ class Propal extends CommonObject
*/
public function setDeliveryDate($user, $delivery_date, $notrigger = 0)
{
- if (!empty($user->rights->propal->creer))
- {
+ if (!empty($user->rights->propal->creer)) {
$error = 0;
$this->db->begin();
@@ -2095,34 +2088,31 @@ class Propal extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->date_livraison = $delivery_date;
$this->delivery_date = $delivery_date;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2144,8 +2134,7 @@ class Propal extends CommonObject
public function set_availability($user, $id, $notrigger = 0)
{
// phpcs:enable
- if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT)
- {
+ if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) {
$error = 0;
$this->db->begin();
@@ -2156,34 +2145,31 @@ class Propal extends CommonObject
dol_syslog(__METHOD__.' availability('.$id.')', LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->fk_availability = $id;
$this->availability_id = $id;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2211,8 +2197,7 @@ class Propal extends CommonObject
public function set_demand_reason($user, $id, $notrigger = 0)
{
// phpcs:enable
- if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT)
- {
+ if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) {
$error = 0;
$this->db->begin();
@@ -2223,36 +2208,33 @@ class Propal extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->fk_input_reason = $id;
$this->demand_reason_id = $id;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2280,8 +2262,7 @@ class Propal extends CommonObject
public function set_ref_client($user, $ref_client, $notrigger = 0)
{
// phpcs:enable
- if (!empty($user->rights->propal->creer))
- {
+ if (!empty($user->rights->propal->creer)) {
$error = 0;
$this->db->begin();
@@ -2291,33 +2272,30 @@ class Propal extends CommonObject
dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->ref_client = $ref_client;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2343,8 +2321,7 @@ class Propal extends CommonObject
// phpcs:enable
$remise = trim($remise) ?trim($remise) : 0;
- if (!empty($user->rights->propal->creer))
- {
+ if (!empty($user->rights->propal->creer)) {
$remise = price2num($remise);
$error = 0;
@@ -2356,34 +2333,31 @@ class Propal extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->remise_percent = $remise;
$this->update_price(1);
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2408,8 +2382,7 @@ class Propal extends CommonObject
// phpcs:enable
$remise = trim($remise) ?trim($remise) : 0;
- if (!empty($user->rights->propal->creer))
- {
+ if (!empty($user->rights->propal->creer)) {
$remise = price2num($remise);
$error = 0;
@@ -2422,34 +2395,31 @@ class Propal extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->remise_absolue = $remise;
$this->update_price(1);
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2478,7 +2448,9 @@ class Propal extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql .= " SET fk_statut = ".$this->statut.",";
- if (!empty($note)) $sql .= " note_private = '".$this->db->escape($note)."',";
+ if (!empty($note)) {
+ $sql .= " note_private = '".$this->db->escape($note)."',";
+ }
$sql .= " date_cloture=NULL, fk_user_cloture=NULL";
$sql .= " WHERE rowid = ".$this->id;
@@ -2487,26 +2459,24 @@ class Propal extends CommonObject
dol_syslog(get_class($this)."::reopen", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
- $error++; $this->errors[] = "Error ".$this->db->lasterror();
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
}
- if (!$error)
- {
- if (!$notrigger)
- {
+ if (!$error) {
+ if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('PROPAL_REOPEN', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
}
// Commit or rollback
- if ($error)
- {
- if (!empty($this->errors))
- {
- foreach ($this->errors as $errmsg)
- {
+ if ($error) {
+ if (!empty($this->errors)) {
+ foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2545,13 +2515,11 @@ class Propal extends CommonObject
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
$triggerName = 'PROPAL_CLOSE_REFUSED';
- if ($status == self::STATUS_SIGNED)
- {
+ if ($status == self::STATUS_SIGNED) {
$triggerName = 'PROPAL_CLOSE_SIGNED';
$modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->model_pdf;
@@ -2560,24 +2528,20 @@ class Propal extends CommonObject
$soc->id = $this->socid;
$result = $soc->set_as_client();
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -2;
}
}
- if ($status == self::STATUS_BILLED) // ->cloture() can also be called when we set it to billed, after setting it to signed
- {
+ if ($status == self::STATUS_BILLED) { // ->cloture() can also be called when we set it to billed, after setting it to signed
$triggerName = 'PROPAL_CLASSIFY_BILLED';
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;
- if (!empty($conf->global->MAIN_MULTILANGS))
- {
+ if (!empty($conf->global->MAIN_MULTILANGS)) {
$outputlangs = new Translate("", $conf);
$newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
$outputlangs->setDefaultLang($newlang);
@@ -2586,24 +2550,23 @@ class Propal extends CommonObject
$this->generateDocument($modelpdf, $outputlangs);
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->statut = $status;
$this->date_cloture = $now;
$this->note_private = $newprivatenote;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger($triggerName, $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -2639,33 +2602,30 @@ class Propal extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->statut = self::STATUS_BILLED;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2688,8 +2648,7 @@ class Propal extends CommonObject
$error = 0;
// Protection
- if ($this->statut <= self::STATUS_DRAFT)
- {
+ if ($this->statut <= self::STATUS_DRAFT) {
return 0;
}
@@ -2702,35 +2661,32 @@ class Propal extends CommonObject
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->statut = self::STATUS_DRAFT;
$this->brouillon = 1;
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -2764,38 +2720,42 @@ class Propal extends CommonObject
$sql = "SELECT s.rowid, s.nom as name, s.client,";
$sql .= " p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
$sql .= " p.datep as dp, p.fin_validite as datelimite";
- if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
+ if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= ", sc.fk_soc, sc.fk_user";
+ }
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
- if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ }
$sql .= " WHERE p.entity IN (".getEntity('propal').")";
$sql .= " AND p.fk_soc = s.rowid";
$sql .= " AND p.fk_statut = c.id";
- if (!$user->rights->societe->client->voir && !$socid) //restriction
- {
+ if (!$user->rights->societe->client->voir && !$socid) { //restriction
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
- if ($socid) $sql .= " AND s.rowid = ".$socid;
- if ($draft) $sql .= " AND p.fk_statut = ".self::STATUS_DRAFT;
- if ($notcurrentuser > 0) $sql .= " AND p.fk_user_author <> ".$user->id;
+ if ($socid) {
+ $sql .= " AND s.rowid = ".$socid;
+ }
+ if ($draft) {
+ $sql .= " AND p.fk_statut = ".self::STATUS_DRAFT;
+ }
+ if ($notcurrentuser > 0) {
+ $sql .= " AND p.fk_user_author <> ".$user->id;
+ }
$sql .= $this->db->order($sortfield, $sortorder);
$sql .= $this->db->plimit($limit, $offset);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$num = $this->db->num_rows($result);
- if ($num)
- {
+ if ($num) {
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($result);
- if ($shortlist == 1)
- {
+ if ($shortlist == 1) {
$ga[$obj->propalid] = $obj->ref;
- } elseif ($shortlist == 2)
- {
+ } elseif ($shortlist == 2) {
$ga[$obj->propalid] = $obj->ref.' ('.$obj->name.')';
} else {
$ga[$i]['id'] = $obj->propalid;
@@ -2837,25 +2797,19 @@ class Propal extends CommonObject
$linkedInvoices = array();
$this->fetchObjectLinked($id, $this->element);
- foreach ($this->linkedObjectsIds as $objecttype => $objectid)
- {
+ foreach ($this->linkedObjectsIds as $objecttype => $objectid) {
// Nouveau système du comon object renvoi des rowid et non un id linéaire de 1 à n
// On parcourt donc une liste d'objets en tant qu'objet unique
- foreach ($objectid as $key => $object)
- {
+ foreach ($objectid as $key => $object) {
// Cas des factures liees directement
- if ($objecttype == 'facture')
- {
+ if ($objecttype == 'facture') {
$linkedInvoices[] = $object;
- } // Cas des factures liees par un autre objet (ex: commande)
- else {
+ } else {
+ // Cas des factures liees par un autre objet (ex: commande)
$this->fetchObjectLinked($object, $objecttype);
- foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid)
- {
- foreach ($subobjectid as $subkey => $subobject)
- {
- if ($subobjecttype == 'facture')
- {
+ foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) {
+ foreach ($subobjectid as $subkey => $subobject) {
+ if ($subobjecttype == 'facture') {
$linkedInvoices[] = $subobject;
}
}
@@ -2864,8 +2818,7 @@ class Propal extends CommonObject
}
}
- if (count($linkedInvoices) > 0)
- {
+ if (count($linkedInvoices) > 0) {
$sql = "SELECT rowid as facid, ref, total, datef as df, fk_user_author, fk_statut, paye";
$sql .= " FROM ".MAIN_DB_PREFIX."facture";
$sql .= " WHERE rowid IN (".implode(',', $linkedInvoices).")";
@@ -2873,12 +2826,10 @@ class Propal extends CommonObject
dol_syslog(get_class($this)."::InvoiceArrayList", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$tab_sqlobj = array();
$nump = $this->db->num_rows($resql);
- for ($i = 0; $i < $nump; $i++)
- {
+ for ($i = 0; $i < $nump; $i++) {
$sqlobj = $this->db->fetch_object($resql);
$tab_sqlobj[] = $sqlobj;
}
@@ -2886,11 +2837,9 @@ class Propal extends CommonObject
$nump = count($tab_sqlobj);
- if ($nump)
- {
+ if ($nump) {
$i = 0;
- while ($i < $nump)
- {
+ while ($i < $nump) {
$obj = array_shift($tab_sqlobj);
$ga[$i] = $obj;
@@ -2902,7 +2851,9 @@ class Propal extends CommonObject
} else {
return -1;
}
- } else return $ga;
+ } else {
+ return $ga;
+ }
}
/**
@@ -2924,7 +2875,9 @@ class Propal extends CommonObject
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('PROPAL_DELETE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
@@ -2944,13 +2897,17 @@ class Propal extends CommonObject
if (!$error) {
// Delete linked object
$res = $this->deleteObjectLinked();
- if ($res < 0) $error++;
+ if ($res < 0) {
+ $error++;
+ }
}
if (!$error) {
// Delete linked contacts
$res = $this->delete_linked_contact();
- if ($res < 0) $error++;
+ if ($res < 0) {
+ $error++;
+ }
}
// Removed extrafields of object
@@ -3032,45 +2989,41 @@ class Propal extends CommonObject
{
global $user;
- if ($this->statut >= self::STATUS_DRAFT)
- {
+ if ($this->statut >= self::STATUS_DRAFT) {
$error = 0;
$this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
$sql .= ' SET fk_availability = '.$availability_id;
- $sql .= ' WHERE rowid='.$this->id;
+ $sql .= ' WHERE rowid='.((int) $this->id);
dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->availability_id = $availability_id;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -3100,45 +3053,41 @@ class Propal extends CommonObject
// phpcs:enable
global $user;
- if ($this->statut >= self::STATUS_DRAFT)
- {
+ if ($this->statut >= self::STATUS_DRAFT) {
$error = 0;
$this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
$sql .= ' SET fk_input_reason = '.$demand_reason_id;
- $sql .= ' WHERE rowid='.$this->id;
+ $sql .= ' WHERE rowid='.((int) $this->id);
dol_syslog(__METHOD__.' demand_reason('.$demand_reason_id.')', LOG_DEBUG);
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->errors[] = $this->db->error();
$error++;
}
- if (!$error)
- {
+ if (!$error) {
$this->oldcopy = clone $this;
$this->demand_reason_id = $demand_reason_id;
}
- if (!$notrigger && empty($error))
- {
+ if (!$notrigger && empty($error)) {
// Call trigger
$result = $this->call_trigger('PROPAL_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
- foreach ($this->errors as $errmsg)
- {
+ foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@@ -3171,10 +3120,8 @@ class Propal extends CommonObject
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->num_rows($result))
- {
+ if ($result) {
+ if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
@@ -3187,15 +3134,13 @@ class Propal extends CommonObject
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
- if ($obj->fk_user_valid)
- {
+ if ($obj->fk_user_valid) {
$vuser = new User($this->db);
$vuser->fetch($obj->fk_user_valid);
$this->user_validation = $vuser;
}
- if ($obj->fk_user_cloture)
- {
+ if ($obj->fk_user_cloture) {
$cluser = new User($this->db);
$cluser->fetch($obj->fk_user_cloture);
$this->user_cloture = $cluser;
@@ -3233,8 +3178,7 @@ class Propal extends CommonObject
global $conf;
// Init/load array of translation of status
- if (empty($this->labelStatus) || empty($this->labelStatusShort))
- {
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
$langs->load("propal");
$this->labelStatus[0] = $langs->transnoentitiesnoconv("PropalStatusDraft");
@@ -3250,11 +3194,17 @@ class Propal extends CommonObject
}
$statusType = '';
- if ($status == self::STATUS_DRAFT) $statusType = 'status0';
- elseif ($status == self::STATUS_VALIDATED) $statusType = 'status1';
- elseif ($status == self::STATUS_SIGNED) $statusType = 'status4';
- elseif ($status == self::STATUS_NOTSIGNED) $statusType = 'status9';
- elseif ($status == self::STATUS_BILLED) $statusType = 'status6';
+ if ($status == self::STATUS_DRAFT) {
+ $statusType = 'status0';
+ } elseif ($status == self::STATUS_VALIDATED) {
+ $statusType = 'status1';
+ } elseif ($status == self::STATUS_SIGNED) {
+ $statusType = 'status4';
+ } elseif ($status == self::STATUS_NOTSIGNED) {
+ $statusType = 'status9';
+ } elseif ($status == self::STATUS_BILLED) {
+ $statusType = 'status6';
+ }
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
@@ -3277,20 +3227,24 @@ class Propal extends CommonObject
$sql = "SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
- if (!$user->rights->societe->client->voir && !$user->socid)
- {
+ if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
$sql .= " WHERE sc.fk_user = ".$user->id;
$clause = " AND";
}
$sql .= $clause." p.entity IN (".getEntity('propal').")";
- if ($mode == 'opened') $sql .= " AND p.fk_statut = ".self::STATUS_VALIDATED;
- if ($mode == 'signed') $sql .= " AND p.fk_statut = ".self::STATUS_SIGNED;
- if ($user->socid) $sql .= " AND p.fk_soc = ".$user->socid;
+ if ($mode == 'opened') {
+ $sql .= " AND p.fk_statut = ".self::STATUS_VALIDATED;
+ }
+ if ($mode == 'signed') {
+ $sql .= " AND p.fk_statut = ".self::STATUS_SIGNED;
+ }
+ if ($user->socid) {
+ $sql .= " AND p.fk_soc = ".$user->socid;
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$langs->load("propal");
$now = dol_now();
@@ -3319,16 +3273,13 @@ class Propal extends CommonObject
$response->img = img_object('', "propal");
// This assignment in condition is not a bug. It allows walking the results.
- while ($obj = $this->db->fetch_object($resql))
- {
+ while ($obj = $this->db->fetch_object($resql)) {
$response->nbtodo++;
$response->total += $obj->total_ht;
- if ($mode == 'opened')
- {
+ if ($mode == 'opened') {
$datelimit = $this->db->jdate($obj->datefin);
- if ($datelimit < ($now - $delay_warning))
- {
+ if ($datelimit < ($now - $delay_warning)) {
$response->nbtodolate++;
}
}
@@ -3364,12 +3315,10 @@ class Propal extends CommonObject
$sql .= $this->db->plimit(100);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num_prods = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num_prods)
- {
+ while ($i < $num_prods) {
$i++;
$row = $this->db->fetch_row($resql);
$prodids[$i] = $row[0];
@@ -3401,8 +3350,7 @@ class Propal extends CommonObject
// Lines
$nbp = 5;
$xnbp = 0;
- while ($xnbp < $nbp)
- {
+ while ($xnbp < $nbp) {
$line = new PropaleLigne($this->db);
$line->desc = $langs->trans("Description")." ".$xnbp;
$line->qty = 1;
@@ -3411,8 +3359,7 @@ class Propal extends CommonObject
$line->tva_tx = 20;
$line->localtax1_tx = 0;
$line->localtax2_tx = 0;
- if ($xnbp == 2)
- {
+ if ($xnbp == 2) {
$line->total_ht = 50;
$line->total_ttc = 60;
$line->total_tva = 10;
@@ -3424,8 +3371,7 @@ class Propal extends CommonObject
$line->remise_percent = 00;
}
- if ($num_prods > 0)
- {
+ if ($num_prods > 0) {
$prodid = mt_rand(1, $num_prods);
$line->fk_product = $prodids[$prodid];
$line->product_ref = 'SPECIMEN';
@@ -3458,8 +3404,7 @@ class Propal extends CommonObject
$sql = "SELECT count(p.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
- if (!$user->rights->societe->client->voir && !$user->socid)
- {
+ if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
$sql .= " WHERE sc.fk_user = ".$user->id;
$clause = "AND";
@@ -3467,11 +3412,9 @@ class Propal extends CommonObject
$sql .= " ".$clause." p.entity IN (".getEntity('propal').")";
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
// This assignment in condition is not a bug. It allows walking the results.
- while ($obj = $this->db->fetch_object($resql))
- {
+ while ($obj = $this->db->fetch_object($resql)) {
$this->nb["proposals"] = $obj->nb;
}
$this->db->free($resql);
@@ -3498,8 +3441,7 @@ class Propal extends CommonObject
$classname = $conf->global->PROPALE_ADDON;
- if (!empty($classname))
- {
+ if (!empty($classname)) {
$mybool = false;
$file = $classname.".php";
@@ -3513,8 +3455,7 @@ class Propal extends CommonObject
$mybool |= @include_once $dir.$file;
}
- if (!$mybool)
- {
+ if (!$mybool) {
dol_print_error('', "Failed to include file ".$file);
return '';
}
@@ -3523,8 +3464,7 @@ class Propal extends CommonObject
$numref = "";
$numref = $obj->getNextValue($soc, $this);
- if ($numref != "")
- {
+ if ($numref != "") {
return $numref;
} else {
$this->error = $obj->error;
@@ -3553,14 +3493,15 @@ class Propal extends CommonObject
{
global $langs, $conf, $user;
- if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
$result = '';
$label = '';
$url = '';
- if ($user->rights->propal->lire)
- {
+ if ($user->rights->propal->lire) {
$label = img_picto('', $this->picto).' '.$langs->trans("Proposal").'';
if (isset($this->statut)) {
$label .= ' '.$this->getLibStatut(5);
@@ -3594,20 +3535,21 @@ class Propal extends CommonObject
$url = DOL_URL_ROOT.'/comm/propal/document.php?id='.$this->id.$get_params;
}
- if ($option != 'nolink')
- {
+ if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
- if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
- if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
}
}
$linkclose = '';
- if (empty($notooltip) && $user->rights->propal->lire)
- {
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
+ if (empty($notooltip) && $user->rights->propal->lire) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("Proposal");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
@@ -3620,8 +3562,12 @@ class Propal extends CommonObject
$linkend = '';
$result .= $linkstart;
- if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
- if ($withpicto != 2) $result .= $this->ref;
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
$result .= $linkend;
if ($addlinktonotes >= 0) {
@@ -3649,7 +3595,9 @@ class Propal extends CommonObject
$txttoshow .= dol_string_nohtmltag($this->note_public, 1);
}
if (!empty($this->note_private)) {
- if (!empty($txttoshow)) $txttoshow .= '
';
+ if (!empty($txttoshow)) {
+ $txttoshow .= '
';
+ }
$txttoshow .= dol_string_nohtmltag($this->note_private, 1);
}
}
@@ -3898,12 +3846,10 @@ class PropaleLigne extends CommonObjectLine
$sql .= ' WHERE pd.rowid = '.$rowid;
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$objp = $this->db->fetch_object($result);
- if ($objp)
- {
+ if ($objp) {
$this->id = $objp->rowid;
$this->rowid = $objp->rowid; // deprecated
$this->fk_propal = $objp->fk_propal;
@@ -3984,32 +3930,70 @@ class PropaleLigne extends CommonObjectLine
$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'.
// Clean parameters
- 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)) $this->remise = 0;
- if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) $this->remise_percent = 0;
- if (empty($this->info_bits)) $this->info_bits = 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_fournprice)) $this->fk_fournprice = 0;
- if (!is_numeric($this->qty)) $this->qty = 0;
- if (empty($this->pa_ht)) $this->pa_ht = 0;
- if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0;
- if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0;
- if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0;
- if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0;
+ 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)) {
+ $this->remise = 0;
+ }
+ if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
+ $this->remise_percent = 0;
+ }
+ if (empty($this->info_bits)) {
+ $this->info_bits = 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_fournprice)) {
+ $this->fk_fournprice = 0;
+ }
+ if (!is_numeric($this->qty)) {
+ $this->qty = 0;
+ }
+ if (empty($this->pa_ht)) {
+ $this->pa_ht = 0;
+ }
+ if (empty($this->multicurrency_subprice)) {
+ $this->multicurrency_subprice = 0;
+ }
+ if (empty($this->multicurrency_total_ht)) {
+ $this->multicurrency_total_ht = 0;
+ }
+ if (empty($this->multicurrency_total_tva)) {
+ $this->multicurrency_total_tva = 0;
+ }
+ if (empty($this->multicurrency_total_ttc)) {
+ $this->multicurrency_total_ttc = 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)
- {
+ 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;
@@ -4017,7 +4001,9 @@ class PropaleLigne extends CommonObjectLine
}
// Check parameters
- if ($this->product_type < 0) return -1;
+ if ($this->product_type < 0) {
+ return -1;
+ }
$this->db->begin();
@@ -4070,26 +4056,21 @@ class PropaleLigne extends CommonObjectLine
dol_syslog(get_class($this).'::insert', LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.'propaldet');
- if (!$error)
- {
+ if (!$error) {
$this->id = $this->rowid;
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('LINEPROPAL_INSERT', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -1;
}
@@ -4121,26 +4102,21 @@ class PropaleLigne extends CommonObjectLine
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE rowid = ".$this->rowid;
dol_syslog("PropaleLigne::delete", LOG_DEBUG);
- if ($this->db->query($sql))
- {
+ if ($this->db->query($sql)) {
// Remove extrafields
- if (!$error)
- {
+ if (!$error) {
$this->id = $this->rowid;
$result = $this->deleteExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('LINEPROPAL_DELETE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -1;
}
@@ -4171,33 +4147,69 @@ class PropaleLigne extends CommonObjectLine
$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'.
- if (empty($this->id) && !empty($this->rowid)) $this->id = $this->rowid;
+ if (empty($this->id) && !empty($this->rowid)) {
+ $this->id = $this->rowid;
+ }
// Clean parameters
- 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->localtax1_type)) $this->localtax1_type = 0;
- if (empty($this->localtax2_type)) $this->localtax2_type = 0;
- if (empty($this->marque_tx)) $this->marque_tx = 0;
- if (empty($this->marge_tx)) $this->marge_tx = 0;
- if (empty($this->price)) $this->price = 0; // TODO A virer
- if (empty($this->remise)) $this->remise = 0; // TODO A virer
- if (empty($this->remise_percent)) $this->remise_percent = 0;
- if (empty($this->info_bits)) $this->info_bits = 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_fournprice)) $this->fk_fournprice = 0;
- if (empty($this->subprice)) $this->subprice = 0;
- if (empty($this->pa_ht)) $this->pa_ht = 0;
+ 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->localtax1_type)) {
+ $this->localtax1_type = 0;
+ }
+ if (empty($this->localtax2_type)) {
+ $this->localtax2_type = 0;
+ }
+ if (empty($this->marque_tx)) {
+ $this->marque_tx = 0;
+ }
+ if (empty($this->marge_tx)) {
+ $this->marge_tx = 0;
+ }
+ if (empty($this->price)) {
+ $this->price = 0; // TODO A virer
+ }
+ if (empty($this->remise)) {
+ $this->remise = 0; // TODO A virer
+ }
+ if (empty($this->remise_percent)) {
+ $this->remise_percent = 0;
+ }
+ if (empty($this->info_bits)) {
+ $this->info_bits = 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_fournprice)) {
+ $this->fk_fournprice = 0;
+ }
+ if (empty($this->subprice)) {
+ $this->subprice = 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)
- {
+ 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;
@@ -4223,8 +4235,7 @@ class PropaleLigne extends CommonObjectLine
$sql .= ", price=".price2num($this->price).""; // TODO A virer
$sql .= ", remise=".price2num($this->remise).""; // TODO A virer
$sql .= ", info_bits='".$this->db->escape($this->info_bits)."'";
- if (empty($this->skip_update_total))
- {
+ if (empty($this->skip_update_total)) {
$sql .= ", total_ht=".price2num($this->total_ht)."";
$sql .= ", total_tva=".price2num($this->total_tva)."";
$sql .= ", total_ttc=".price2num($this->total_ttc)."";
@@ -4233,9 +4244,13 @@ class PropaleLigne extends CommonObjectLine
}
$sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null");
$sql .= ", buy_price_ht=".price2num($this->pa_ht);
- if (strlen($this->special_code)) $sql .= ", special_code=".$this->special_code;
+ if (strlen($this->special_code)) {
+ $sql .= ", special_code=".$this->special_code;
+ }
$sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
- if (!empty($this->rang)) $sql .= ", rang=".$this->rang;
+ if (!empty($this->rang)) {
+ $sql .= ", rang=".$this->rang;
+ }
$sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
$sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
$sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
@@ -4250,23 +4265,18 @@ class PropaleLigne extends CommonObjectLine
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- if (!$error)
- {
+ if ($resql) {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('LINEPROPAL_UPDATE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -1;
}
@@ -4304,8 +4314,7 @@ class PropaleLigne extends CommonObjectLine
dol_syslog("PropaleLigne::update_total", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->db->commit();
return 1;
} else {
diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php
index ca95be53fc1..f64bc31c6ac 100644
--- a/htdocs/comm/propal/class/propalestats.class.php
+++ b/htdocs/comm/propal/class/propalestats.class.php
@@ -69,8 +69,7 @@ class PropaleStats extends Stats
$this->userid = $userid;
$this->join = '';
- if ($mode == 'customer')
- {
+ if ($mode == 'customer') {
$object = new Propal($this->db);
$this->from = MAIN_DB_PREFIX.$object->table_element." as p";
@@ -81,8 +80,7 @@ class PropaleStats extends Stats
//$this->where .= " p.fk_statut > 0";
}
- if ($mode == 'supplier')
- {
+ if ($mode == 'supplier') {
$object = new SupplierProposal($this->db);
$this->from = MAIN_DB_PREFIX.$object->table_element." as p";
@@ -95,21 +93,22 @@ class PropaleStats extends Stats
}
//$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity;
$this->where .= ($this->where ? ' AND ' : '')."p.entity IN (".getEntity('propal').")";
- if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
- if ($this->socid)
- {
+ if (!$user->rights->societe->client->voir && !$this->socid) {
+ $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
+ }
+ if ($this->socid) {
$this->where .= " AND p.fk_soc = ".$this->socid;
}
- if ($this->userid > 0) $this->where .= ' AND fk_user_author = '.$this->userid;
+ if ($this->userid > 0) {
+ $this->where .= ' AND fk_user_author = '.$this->userid;
+ }
- if ($typentid)
- {
+ if ($typentid) {
$this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
$this->where .= ' AND s.fk_typent = '.$typentid;
}
- if ($categid)
- {
+ if ($categid) {
$this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_societe as cs ON cs.fk_soc = p.fk_soc';
$this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as c ON c.rowid = cs.fk_categorie';
$this->where .= ' AND c.rowid = '.$categid;
@@ -130,7 +129,9 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
- if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$user->socid) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ }
$sql .= $this->join;
$sql .= " WHERE ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
$sql .= " AND ".$this->where;
@@ -153,7 +154,9 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(".$this->field_date.",'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$this->socid) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ }
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY dm";
@@ -175,7 +178,9 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, SUM(p.".$this->field.")";
$sql .= " FROM ".$this->from;
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$this->socid) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ }
$sql .= $this->join;
$sql .= " WHERE ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
$sql .= " AND ".$this->where;
@@ -198,7 +203,9 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, AVG(p.".$this->field.")";
$sql .= " FROM ".$this->from;
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$this->socid) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ }
$sql .= $this->join;
$sql .= " WHERE ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
$sql .= " AND ".$this->where;
@@ -219,7 +226,9 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(".$this->field_date.",'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$this->socid) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ }
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
@@ -243,7 +252,9 @@ class PropaleStats extends Stats
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
$sql .= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
- if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$user->socid) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ }
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " AND p.rowid = tl.fk_propal AND tl.fk_product = product.rowid";
diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php
index af3679de945..60d3836cfcb 100644
--- a/htdocs/comm/propal/contact.php
+++ b/htdocs/comm/propal/contact.php
@@ -33,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
// Load translation files required by the page
-$langs->loadLangs(array('facture', 'orders', 'sendings', 'companies'));
+$langs->loadLangs(array('facture', 'propal', 'orders', 'sendings', 'companies'));
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
@@ -41,28 +41,26 @@ $lineid = GETPOST('lineid', 'int');
$action = GETPOST('action', 'aZ09');
// Security check
-if ($user->socid) $socid = $user->socid;
+if ($user->socid) {
+ $socid = $user->socid;
+}
$result = restrictedArea($user, 'propal', $id);
$object = new Propal($db);
// Load object
-if ($id > 0 || !empty($ref))
-{
+if ($id > 0 || !empty($ref)) {
$ret = $object->fetch($id, $ref);
- if ($ret == 0)
- {
+ if ($ret == 0) {
$langs->load("errors");
setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
$error++;
- } elseif ($ret < 0)
- {
+ } elseif ($ret < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
-if (!$error)
-{
+if (!$error) {
$object->fetch_thirdparty();
} else {
header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
@@ -74,42 +72,34 @@ if (!$error)
* Add a new contact
*/
-if ($action == 'addcontact' && $user->rights->propale->creer)
-{
- if ($object->id > 0)
- {
+if ($action == 'addcontact' && $user->rights->propale->creer) {
+ if ($object->id > 0) {
$contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
}
- if ($result >= 0)
- {
+ if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
- if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
-} // Toggle the status of a contact
-elseif ($action == 'swapstatut' && $user->rights->propale->creer)
-{
- if ($object->id > 0)
- {
+} elseif ($action == 'swapstatut' && $user->rights->propale->creer) {
+ // Toggle the status of a contact
+ if ($object->id > 0) {
$result = $object->swapContactStatus(GETPOST('ligne'));
}
-} // Deletes a contact
-elseif ($action == 'deletecontact' && $user->rights->propale->creer)
-{
+} elseif ($action == 'deletecontact' && $user->rights->propale->creer) {
+ // Deletes a contact
$result = $object->delete_contact($lineid);
- if ($result >= 0)
- {
+ if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
@@ -134,8 +124,7 @@ $form = new Form($db);
$formcompany = new FormCompany($db);
$formother = new FormOther($db);
-if ($object->id > 0)
-{
+if ($object->id > 0) {
$head = propal_prepare_head($object);
print dol_get_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal');
@@ -152,12 +141,10 @@ if ($object->id > 0)
// Thirdparty
$morehtmlref .= ' '.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
// Project
- if (!empty($conf->projet->enabled))
- {
+ if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= ' '.$langs->trans('Project').' ';
- if ($user->rights->propal->creer)
- {
+ if ($user->rights->propal->creer) {
if ($action != 'classify') {
//$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '';
$morehtmlref .= ' : ';
@@ -194,10 +181,11 @@ if ($object->id > 0)
// Contacts lines (modules that overwrite templates must declare this into descriptor)
$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
- foreach ($dirtpls as $reldir)
- {
+ foreach ($dirtpls as $reldir) {
$res = @include dol_buildpath($reldir.'/contacts.tpl.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
}
diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php
index fbe7fdbec5c..4c408adcb28 100644
--- a/htdocs/comm/propal/document.php
+++ b/htdocs/comm/propal/document.php
@@ -39,15 +39,14 @@ if (!empty($conf->projet->enabled)) {
// Load translation files required by the page
$langs->loadLangs(array('compta', 'other', 'companies'));
-$action = GETPOST('action', 'alpha');
-$confirm = GETPOST('confirm', 'alpha');
-$id = GETPOST('id', 'int');
-$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'alpha');
+$confirm = GETPOST('confirm', 'alpha');
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
// Security check
$socid = '';
-if (!empty($user->socid))
-{
+if (!empty($user->socid)) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'propal', $id);
@@ -57,16 +56,26 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
-if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
+if (empty($page) || $page == -1) {
+ $page = 0;
+} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
-if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) { $sortfield = $conf->global->MAIN_DOC_SORT_FIELD; }
-if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) { $sortorder = $conf->global->MAIN_DOC_SORT_ORDER; }
+if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) {
+ $sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
+}
+if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) {
+ $sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
+}
-if (!$sortorder) $sortorder = "ASC";
-if (!$sortfield) $sortfield = "name";
+if (!$sortorder) {
+ $sortorder = "ASC";
+}
+if (!$sortfield) {
+ $sortfield = "name";
+}
$object = new Propal($db);
$object->fetch($id, $ref);
@@ -76,11 +85,10 @@ $object->fetch($id, $ref);
* Actions
*/
-if ($object->id > 0)
-{
+if ($object->id > 0) {
$object->fetch_thirdparty();
$upload_dir = $conf->propal->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
- include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
+ include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
}
@@ -92,8 +100,7 @@ llxHeader('', $langs->trans('Proposal'), 'EN:Commercial_Proposals|FR:Proposition
$form = new Form($db);
-if ($object->id > 0)
-{
+if ($object->id > 0) {
$upload_dir = $conf->propal->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
$head = propal_prepare_head($object);
@@ -102,8 +109,7 @@ if ($object->id > 0)
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0;
- foreach ($filearray as $key => $file)
- {
+ foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}
@@ -120,12 +126,10 @@ if ($object->id > 0)
// Thirdparty
$morehtmlref .= ' '.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
// Project
- if (!empty($conf->projet->enabled))
- {
+ if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= ' '.$langs->trans('Project').' ';
- if ($user->rights->propal->creer)
- {
+ if ($user->rights->propal->creer) {
if ($action != 'classify') {
//$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '';
$morehtmlref .= ' : ';
diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php
index b51f138b0e5..812561a63b1 100644
--- a/htdocs/comm/propal/index.php
+++ b/htdocs/comm/propal/index.php
@@ -20,7 +20,7 @@
*/
/**
- * \file htdocs/comm/propal/index.php
+ * \file htdocs/comm/propal/index.php
* \ingroup propal
* \brief Home page of proposal area
*/
@@ -29,8 +29,7 @@ require '../../main.inc.php';
// Security check
$socid = GETPOST('socid', 'int');
-if (isset($user->socid) && $user->socid > 0)
-{
+if (isset($user->socid) && $user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@@ -66,8 +65,7 @@ print '';
print ' ';
// This is useless due to the global search combo
-if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))
-{
+if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
print ' |