diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index fe7acc7b568..9d85b9a1223 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -94,9 +94,7 @@ if ($id > 0 || ! empty($ref)) {
}
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
-$hookmanager->initHooks(array (
- 'propalcard'
-));
+$hookmanager->initHooks(array('propalcard'));
$permissionnote = $user->rights->propale->creer; // Used by the include of actions_setnotes.inc.php
@@ -104,13 +102,12 @@ $permissionnote = $user->rights->propale->creer; // Used by the include of actio
* Actions
*/
-$parameters = array (
- 'socid' => $socid
-);
-$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+$parameters = array('socid' => $socid);
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
+ // hooks
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once
-
+
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes') {
if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) {
@@ -574,7 +571,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
// Unset extrafield
if (is_array($extralabelsline)) {
// Get extra fields
- foreach ( $extralabelsline as $key => $value ) {
+ foreach ($extralabelsline as $key => $value) {
unset($_POST ["options_" . $key]);
}
}
@@ -634,9 +631,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
$prodcustprice = new Productcustomerprice($db);
- $filter = array (
- 't.fk_product' => $prod->id,'t.fk_soc' => $object->client->id
- );
+ $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->client->id);
$result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
if ($result) {
@@ -818,7 +813,7 @@ else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('sa
// Unset extrafield
if (is_array($extralabelsline)) {
// Get extra fields
- foreach ( $extralabelsline as $key => $value ) {
+ foreach ($extralabelsline as $key => $value) {
unset($_POST ["options_" . $key]);
}
}
@@ -1026,14 +1021,11 @@ else if ($action == 'down' && $user->rights->propal->creer) {
if (! $error) {
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
- $hookmanager->initHooks(array (
- 'propaldao'
- ));
- $parameters = array (
- 'id' => $object->id
- );
- $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by
- // some hooks
+ $hookmanager->initHooks(array('propaldao'));
+ $parameters = array('id' => $object->id);
+ $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified by
+ // some hooks
if (empty($reshook)) {
$result = $object->insertExtraFields();
if ($result < 0) {
@@ -1243,11 +1235,10 @@ if ($action == 'create') {
}
// Other attributes
- $parameters = array (
- 'colspan' => ' colspan="3"'
- );
- $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
- // hook
+ $parameters = array('colspan' => ' colspan="3"');
+ $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified
+ // by
+ // hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
print $object->showOptionals($extrafields, 'edit');
}
@@ -1270,7 +1261,7 @@ if ($action == 'create') {
print '
';
print '' . $langs->trans("CopyPropalFrom") . ' ';
print '';
- $liste_propal = array ();
+ $liste_propal = array();
$liste_propal [0] = '';
$sql = "SELECT p.rowid as id, p.ref, s.nom";
@@ -1285,7 +1276,7 @@ if ($action == 'create') {
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- while ( $i < $num ) {
+ while ($i < $num) {
$row = $db->fetch_row($resql);
$propalRefAndSocName = $row [1] . " - " . $row [2];
$liste_propal [$row [0]] = $propalRefAndSocName;
@@ -1358,14 +1349,12 @@ if ($action == 'create') {
// Clone confirmation
if ($action == 'clone') {
// Create an array for form
- $formquestion = array (
- // 'text' => $langs->trans("ConfirmClone"),
- // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array (
- 'type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)')
- )
- );
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
+ // 1),
+ array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)')));
// Paiement incomplet. On demande si motif = escompte ou autre
$formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ClonePropal'), $langs->trans('ConfirmClonePropal', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
}
@@ -1414,11 +1403,10 @@ if ($action == 'create') {
}
if (! $formconfirm) {
- $parameters = array (
- 'lineid' => $lineid
- );
- $formconfirm = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by
- // hook
+ $parameters = array('lineid' => $lineid);
+ $formconfirm = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified
+ // by
+ // hook
}
// Print form confirm
@@ -1685,13 +1673,12 @@ if ($action == 'create') {
// Other attributes (TODO Move this into an include)
$res = $object->fetch_optionals($object->id, $extralabels);
- $parameters = array (
- 'colspan' => ' colspan="3"'
- );
- $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
- // hook
+ $parameters = array('colspan' => ' colspan="3"');
+ $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified
+ // by
+ // hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
- foreach ( $extrafields->attribute_label as $key => $label ) {
+ foreach ($extrafields->attribute_label as $key => $label) {
if ($action == 'edit_extras') {
$value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
} else {
@@ -1705,9 +1692,7 @@ if ($action == 'create') {
print ' class="fieldrequired"';
print '>' . $label . ' ';
// Convert date into timestamp format
- if (in_array($extrafields->attribute_type [$key], array (
- 'date','datetime'
- ))) {
+ if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) {
$value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]);
}
@@ -1829,9 +1814,10 @@ if ($action == 'create') {
}
}
- $parameters = array ();
- $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified
- // by hook
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified
+ // by hook
}
}
@@ -1875,9 +1861,9 @@ if ($action == 'create') {
if ($action != 'presend') {
print '';
- $parameters = array ();
+ $parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
- // modified by hook
+ // modified by hook
if (empty($reshook)) {
if ($action != 'statut' && $action != 'editline') {
// Validate
@@ -1888,7 +1874,8 @@ if ($action == 'create') {
}
// 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
+ // "workflow" action so should appears somewhere
+ // else on
// page.
{
print '
' . $langs->trans("AddAction") . ' ';
@@ -2042,8 +2029,8 @@ if ($action == 'create') {
$formmail->fromname = $user->getFullName($langs);
$formmail->frommail = $user->email;
$formmail->withfrom = 1;
- $liste = array ();
- foreach ( $object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value )
+ $liste = array();
+ foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
$liste [$key] = $value;
$formmail->withto = GETPOST("sendto") ? GETPOST("sendto") : $liste;
$formmail->withtocc = $liste;
@@ -2067,11 +2054,11 @@ if ($action == 'create') {
// Find the good contact adress
$custcontact = '';
- $contactarr = array ();
+ $contactarr = array();
$contactarr = $object->liste_contact(- 1, 'external');
if (is_array($contactarr) && count($contactarr) > 0) {
- foreach ( $contactarr as $contact ) {
+ foreach ($contactarr as $contact) {
if ($contact ['libelle'] == $langs->trans('TypeContact_propal_external_CUSTOMER')) {
$contactstatic = new Contact($db);
$contactstatic->fetch($contact ['id']);
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 6e2c337984f..1a209234612 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -25,27 +25,26 @@
*/
/**
- * \file htdocs/commande/fiche.php
- * \ingroup commande
- * \brief Page to show customer order
+ * \file htdocs/commande/fiche.php
+ * \ingroup commande
+ * \brief Page to show customer order
*/
-
require '../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
-require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
-require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
-require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
-require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formorder.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/modules/commande/modules_commande.php';
+require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
+require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/order.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
if (! empty($conf->propal->enabled))
- require DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
+ require DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
if (! empty($conf->projet->enabled)) {
- require DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
+ require DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
}
-require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
$langs->load('orders');
$langs->load('sendings');
@@ -57,1349 +56,1145 @@ $langs->load('products');
if (! empty($conf->margin->enabled))
$langs->load('margins');
-$id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('orderid','int'));
-$ref=GETPOST('ref','alpha');
-$socid=GETPOST('socid','int');
-$action=GETPOST('action','alpha');
-$confirm=GETPOST('confirm','alpha');
-$lineid=GETPOST('lineid','int');
-$origin=GETPOST('origin','alpha');
-$originid=(GETPOST('originid','int')?GETPOST('originid','int'):GETPOST('origin_id','int')); // For backward compatibility
+$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('orderid', 'int'));
+$ref = GETPOST('ref', 'alpha');
+$socid = GETPOST('socid', 'int');
+$action = GETPOST('action', 'alpha');
+$confirm = GETPOST('confirm', 'alpha');
+$lineid = GETPOST('lineid', 'int');
+$origin = GETPOST('origin', 'alpha');
+$originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
-$mesg = GETPOST('mesg');
+$mesg = GETPOST('mesg');
-//PDF
-$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
-$hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
-$hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
+// PDF
+$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
+$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
+$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
// Security check
-if (! empty($user->societe_id)) $socid=$user->societe_id;
-$result=restrictedArea($user,'commande',$id);
+if (! empty($user->societe_id))
+ $socid = $user->societe_id;
+$result = restrictedArea($user, 'commande', $id);
$object = new Commande($db);
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
-$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
-if ($id > 0 || ! empty($ref))
-{
- $ret=$object->fetch($id, $ref);
- $ret=$object->fetch_thirdparty();
+if ($id > 0 || ! empty($ref)) {
+ $ret = $object->fetch($id, $ref);
+ $ret = $object->fetch_thirdparty();
}
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('ordercard'));
-$permissionnote=$user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php
-
+$permissionnote = $user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php
/*
* Actions
*/
-$parameters=array('socid'=>$socid);
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
-
-include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
+$parameters = array('socid' => $socid);
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once
+
// Action clone object
-if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->commande->creer)
-{
- if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
- {
- $mesg='
'.$langs->trans("NoCloneOptionsSpecified").'
';
- }
- else
- {
- if ($object->id > 0)
- {
- $result=$object->createFromClone($socid);
- if ($result > 0)
- {
- header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
- exit;
- }
- else
- {
- $mesg='
'.$object->error.'
';
- $action='';
+if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->commande->creer) {
+ if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) {
+ $mesg = '
' . $langs->trans("NoCloneOptionsSpecified") . '
';
+ } else {
+ if ($object->id > 0) {
+ $result = $object->createFromClone($socid);
+ if ($result > 0) {
+ header("Location: " . $_SERVER ['PHP_SELF'] . '?id=' . $result);
+ exit();
+ } else {
+ $mesg = '
' . $object->error . '
';
+ $action = '';
}
}
}
-}
+}
// Reopen a closed order
-else if ($action == 'reopen' && $user->rights->commande->creer)
-{
- if ($object->statut == 3)
- {
+else if ($action == 'reopen' && $user->rights->commande->creer) {
+ if ($object->statut == 3) {
$result = $object->set_reopen($user);
- if ($result > 0)
- {
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- }
- else
- {
- $mesg='
'.$object->error.'
';
+ if ($result > 0) {
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?id=' . $object->id);
+ exit();
+ } else {
+ $mesg = '
' . $object->error . '
';
}
}
-}
+}
// Suppression de la commande
-else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->commande->supprimer)
-{
- $result=$object->delete($user);
- if ($result > 0)
- {
+else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->commande->supprimer) {
+ $result = $object->delete($user);
+ if ($result > 0) {
header('Location: index.php');
- exit;
+ exit();
+ } else {
+ $mesg = '
' . $object->error . '
';
}
- else
- {
- $mesg='
'.$object->error.'
';
- }
-}
+}
// Remove a product line
-else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer)
-{
+else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer) {
$result = $object->deleteline($lineid);
- if ($result > 0)
- {
+ if ($result > 0) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
+ $newlang = GETPOST('lang_id');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $ret=$object->fetch($object->id); // Reload to get new records
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $ret = $object->fetch($object->id); // Reload to get new records
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
-
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
+
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?id=' . $object->id);
+ exit();
+ } else {
+ $mesg = '
' . $object->error . '
';
}
- else
- {
- $mesg='
'.$object->error.'
';
- }
-}
+}
// Categorisation dans projet
-else if ($action == 'classin' && $user->rights->commande->creer)
-{
+else if ($action == 'classin' && $user->rights->commande->creer) {
$object->setProject(GETPOST('projectid'));
-}
+}
// Add order
-else if ($action == 'add' && $user->rights->commande->creer)
-{
- $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
- $datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'),GETPOST('liv_day'),GETPOST('liv_year'));
-
- if ($datecommande == '')
- {
- $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')).'
';
- $action='create';
- $error++;
+else if ($action == 'add' && $user->rights->commande->creer) {
+ $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
+ $datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
+
+ if ($datecommande == '') {
+ $mesg = '
' . $langs->trans('ErrorFieldRequired', $langs->transnoentities('Date')) . '
';
+ $action = 'create';
+ $error ++;
}
-
- if ($socid<1)
- {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Customer")),'errors');
- $action='create';
- $error++;
+
+ if ($socid < 1) {
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), 'errors');
+ $action = 'create';
+ $error ++;
}
-
- if (! $error)
- {
- $object->socid=$socid;
+
+ if (! $error) {
+ $object->socid = $socid;
$object->fetch_thirdparty();
-
+
$db->begin();
-
- $object->date_commande = $datecommande;
- $object->note_private = GETPOST('note_private');
- $object->note_public = GETPOST('note_public');
- $object->source = GETPOST('source_id');
- $object->fk_project = GETPOST('projectid');
- $object->ref_client = GETPOST('ref_client');
- $object->modelpdf = GETPOST('model');
- $object->cond_reglement_id = GETPOST('cond_reglement_id');
- $object->mode_reglement_id = GETPOST('mode_reglement_id');
- $object->availability_id = GETPOST('availability_id');
- $object->demand_reason_id = GETPOST('demand_reason_id');
- $object->date_livraison = $datelivraison;
- $object->fk_delivery_address = GETPOST('fk_address');
- $object->contactid = GETPOST('contactidp');
-
+
+ $object->date_commande = $datecommande;
+ $object->note_private = GETPOST('note_private');
+ $object->note_public = GETPOST('note_public');
+ $object->source = GETPOST('source_id');
+ $object->fk_project = GETPOST('projectid');
+ $object->ref_client = GETPOST('ref_client');
+ $object->modelpdf = GETPOST('model');
+ $object->cond_reglement_id = GETPOST('cond_reglement_id');
+ $object->mode_reglement_id = GETPOST('mode_reglement_id');
+ $object->availability_id = GETPOST('availability_id');
+ $object->demand_reason_id = GETPOST('demand_reason_id');
+ $object->date_livraison = $datelivraison;
+ $object->fk_delivery_address = GETPOST('fk_address');
+ $object->contactid = GETPOST('contactidp');
+
// If creation from another object of another module (Example: origin=propal, originid=1)
- if (! empty($origin) && ! empty($originid))
- {
+ if (! empty($origin) && ! empty($originid)) {
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin;
- if (preg_match('/^([^_]+)_([^_]+)/i',$origin,$regs))
- {
- $element = $regs[1];
- $subelement = $regs[2];
+ if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
+ $element = $regs [1];
+ $subelement = $regs [2];
}
-
+
// For compatibility
- if ($element == 'order') {
+ if ($element == 'order') {
$element = $subelement = 'commande';
}
- if ($element == 'propal') {
- $element = 'comm/propal'; $subelement = 'propal';
+ if ($element == 'propal') {
+ $element = 'comm/propal';
+ $subelement = 'propal';
}
if ($element == 'contract') {
$element = $subelement = 'contrat';
}
-
- $object->origin = $origin;
+
+ $object->origin = $origin;
$object->origin_id = $originid;
-
+
// Possibility to add external linked objects with hooks
- $object->linked_objects[$object->origin] = $object->origin_id;
- $other_linked_objects=GETPOST('other_linked_objects','array');
- if (! empty($other_linked_objects))
- {
+ $object->linked_objects [$object->origin] = $object->origin_id;
+ $other_linked_objects = GETPOST('other_linked_objects', 'array');
+ if (! empty($other_linked_objects)) {
$object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
}
-
+
// Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
- if($ret < 0)
- $error++;
-
- if(!$error) {
+ $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
+ if ($ret < 0)
+ $error ++;
+
+ if (! $error) {
$object_id = $object->create($user);
-
- if ($object_id > 0)
- {
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
-
+
+ if ($object_id > 0) {
+ dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
+
$classname = ucfirst($subelement);
$srcobject = new $classname($db);
-
- dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
- $result=$srcobject->fetch($object->origin_id);
- if ($result > 0)
- {
+
+ dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
+ $result = $srcobject->fetch($object->origin_id);
+ if ($result > 0) {
$lines = $srcobject->lines;
- if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
-
- $fk_parent_line=0;
- $num=count($lines);
-
- for ($i=0;$i<$num;$i++)
- {
- $label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
- $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
- $product_type=(! empty($lines[$i]->product_type)?$lines[$i]->product_type:0);
-
+ if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
+ $lines = $srcobject->fetch_lines();
+
+ $fk_parent_line = 0;
+ $num = count($lines);
+
+ for($i = 0; $i < $num; $i ++) {
+ $label = (! empty($lines [$i]->label) ? $lines [$i]->label : '');
+ $desc = (! empty($lines [$i]->desc) ? $lines [$i]->desc : $lines [$i]->libelle);
+ $product_type = (! empty($lines [$i]->product_type) ? $lines [$i]->product_type : 0);
+
// Dates
// TODO mutualiser
- $date_start=$lines[$i]->date_debut_prevue;
- if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
- if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
- $date_end=$lines[$i]->date_fin_prevue;
- if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
- if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
-
- // Reset fk_parent_line for no child products and special product
- if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
+ $date_start = $lines [$i]->date_debut_prevue;
+ if ($lines [$i]->date_debut_reel)
+ $date_start = $lines [$i]->date_debut_reel;
+ if ($lines [$i]->date_start)
+ $date_start = $lines [$i]->date_start;
+ $date_end = $lines [$i]->date_fin_prevue;
+ if ($lines [$i]->date_fin_reel)
+ $date_end = $lines [$i]->date_fin_reel;
+ if ($lines [$i]->date_end)
+ $date_end = $lines [$i]->date_end;
+
+ // Reset fk_parent_line for no child products and special product
+ if (($lines [$i]->product_type != 9 && empty($lines [$i]->fk_parent_line)) || $lines [$i]->product_type == 9) {
$fk_parent_line = 0;
}
-
- //Extrafields
- if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i],'fetch_optionals') ) // For avoid conflicts if trigger used
+
+ // Extrafields
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines [$i], 'fetch_optionals')) // For avoid conflicts if
+ // trigger used
{
- $lines[$i]->fetch_optionals($lines[$i]->rowid);
- $array_option=$lines[$i]->array_options;
+ $lines [$i]->fetch_optionals($lines [$i]->rowid);
+ $array_option = $lines [$i]->array_options;
}
-
- $result = $object->addline(
- $desc,
- $lines[$i]->subprice,
- $lines[$i]->qty,
- $lines[$i]->tva_tx,
- $lines[$i]->localtax1_tx,
- $lines[$i]->localtax2_tx,
- $lines[$i]->fk_product,
- $lines[$i]->remise_percent,
- $lines[$i]->info_bits,
- $lines[$i]->fk_remise_except,
- 'HT',
- 0,
- $date_start,
- $date_end,
- $product_type,
- $lines[$i]->rang,
- $lines[$i]->special_code,
- $fk_parent_line,
- $lines[$i]->fk_fournprice,
- $lines[$i]->pa_ht,
- $label,
- $array_option
- );
-
- if ($result < 0)
- {
- $error++;
+
+ $result = $object->addline($desc, $lines [$i]->subprice, $lines [$i]->qty, $lines [$i]->tva_tx, $lines [$i]->localtax1_tx, $lines [$i]->localtax2_tx, $lines [$i]->fk_product, $lines [$i]->remise_percent, $lines [$i]->info_bits, $lines [$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines [$i]->rang, $lines [$i]->special_code, $fk_parent_line, $lines [$i]->fk_fournprice, $lines [$i]->pa_ht, $label, $array_option);
+
+ if ($result < 0) {
+ $error ++;
break;
}
-
+
// Defined the new fk_parent_line
- if ($result > 0 && $lines[$i]->product_type == 9) {
+ if ($result > 0 && $lines [$i]->product_type == 9) {
$fk_parent_line = $result;
}
}
-
+
// Hooks
- $parameters=array('objFrom'=>$srcobject);
- $reshook=$hookmanager->executeHooks('createFrom',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if ($reshook < 0) $error++;
- }
- else
- {
- $mesg=$srcobject->error;
- $error++;
+ $parameters = array('objFrom' => $srcobject);
+ $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified by hook
+ if ($reshook < 0)
+ $error ++;
+ } else {
+ $mesg = $srcobject->error;
+ $error ++;
}
+ } else {
+ $mesg = $object->error;
+ $error ++;
}
- else
- {
- $mesg=$object->error;
- $error++;
- }
- }
- else
- {
+ } else {
// Required extrafield left blank, error message already defined by setOptionalsFromPost()
- $action='create';
+ $action = 'create';
}
- }
- else
- {
+ } else {
// Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
- if($ret < 0)
- $error++;
-
- if(!$error) {
+ $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
+ if ($ret < 0)
+ $error ++;
+
+ if (! $error) {
$object_id = $object->create($user);
-
+
// If some invoice's lines already known
- $NBLINES=8;
- for ($i = 1 ; $i <= $NBLINES ; $i++)
- {
- if ($_POST['idprod'.$i])
- {
- $xid = 'idprod'.$i;
- $xqty = 'qty'.$i;
- $xremise = 'remise_percent'.$i;
- $object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
+ $NBLINES = 8;
+ for($i = 1; $i <= $NBLINES; $i ++) {
+ if ($_POST ['idprod' . $i]) {
+ $xid = 'idprod' . $i;
+ $xqty = 'qty' . $i;
+ $xremise = 'remise_percent' . $i;
+ $object->add_product($_POST [$xid], $_POST [$xqty], $_POST [$xremise]);
}
}
}
}
-
+
// Insert default contacts if defined
- if ($object_id > 0)
- {
- if (GETPOST('contactidp'))
- {
- $result=$object->add_contact(GETPOST('contactidp'),'CUSTOMER','external');
- if ($result < 0)
- {
- $mesg = '
'.$langs->trans("ErrorFailedToAddContact").'
';
- $error++;
+ if ($object_id > 0) {
+ if (GETPOST('contactidp')) {
+ $result = $object->add_contact(GETPOST('contactidp'), 'CUSTOMER', 'external');
+ if ($result < 0) {
+ $mesg = '
' . $langs->trans("ErrorFailedToAddContact") . '
';
+ $error ++;
}
}
-
+
$id = $object_id;
$action = '';
}
-
+
// End of object creation, we show it
- if ($object_id > 0 && ! $error)
- {
+ if ($object_id > 0 && ! $error) {
$db->commit();
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object_id);
- exit;
- }
- else
- {
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?id=' . $object_id);
+ exit();
+ } else {
$db->rollback();
- $action='create';
- if (! $mesg) $mesg='
'.$object->error.'
';
+ $action = 'create';
+ if (! $mesg)
+ $mesg = '
' . $object->error . '
';
}
}
-}
+}
-else if ($action == 'classifybilled' && $user->rights->commande->creer)
-{
- $ret=$object->classifyBilled();
-}
+else if ($action == 'classifybilled' && $user->rights->commande->creer) {
+ $ret = $object->classifyBilled();
+}
// Positionne ref commande client
-else if ($action == 'set_ref_client' && $user->rights->commande->creer)
-{
+else if ($action == 'set_ref_client' && $user->rights->commande->creer) {
$object->set_ref_client($user, GETPOST('ref_client'));
-}
+}
-else if ($action == 'setremise' && $user->rights->commande->creer)
-{
+else if ($action == 'setremise' && $user->rights->commande->creer) {
$object->set_remise($user, GETPOST('remise'));
-}
+}
-else if ($action == 'setabsolutediscount' && $user->rights->commande->creer)
-{
- if (GETPOST('remise_id'))
- {
- if ($object->id > 0)
- {
+else if ($action == 'setabsolutediscount' && $user->rights->commande->creer) {
+ if (GETPOST('remise_id')) {
+ if ($object->id > 0) {
$object->insert_discount(GETPOST('remise_id'));
- }
- else
- {
- dol_print_error($db,$object->error);
+ } else {
+ dol_print_error($db, $object->error);
}
}
-}
+}
-else if ($action == 'setdate' && $user->rights->commande->creer)
-{
- //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
- $date=dol_mktime(0, 0, 0, GETPOST('order_month'), GETPOST('order_day'), GETPOST('order_year'));
-
- $result=$object->set_date($user,$date);
- if ($result < 0)
- {
- $mesg='
'.$object->error.'
';
+else if ($action == 'setdate' && $user->rights->commande->creer) {
+ // print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
+ $date = dol_mktime(0, 0, 0, GETPOST('order_month'), GETPOST('order_day'), GETPOST('order_year'));
+
+ $result = $object->set_date($user, $date);
+ if ($result < 0) {
+ $mesg = '
' . $object->error . '
';
}
-}
+}
-else if ($action == 'setdate_livraison' && $user->rights->commande->creer)
-{
- //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
- $datelivraison=dol_mktime(0, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
-
- $result=$object->set_date_livraison($user,$datelivraison);
- if ($result < 0)
- {
- $mesg='
'.$object->error.'
';
+else if ($action == 'setdate_livraison' && $user->rights->commande->creer) {
+ // print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
+ $datelivraison = dol_mktime(0, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
+
+ $result = $object->set_date_livraison($user, $datelivraison);
+ if ($result < 0) {
+ $mesg = '
' . $object->error . '
';
}
-}
+}
-else if ($action == 'setmode' && $user->rights->commande->creer)
-{
- $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
- if ($result < 0) dol_print_error($db,$object->error);
-}
-
-else if ($action == 'setavailability' && $user->rights->commande->creer)
-{
- $result=$object->availability(GETPOST('availability_id'));
- if ($result < 0) dol_print_error($db,$object->error);
-}
-
-else if ($action == 'setdemandreason' && $user->rights->commande->creer)
-{
- $result=$object->demand_reason(GETPOST('demand_reason_id'));
- if ($result < 0) dol_print_error($db,$object->error);
-}
-
-else if ($action == 'setconditions' && $user->rights->commande->creer)
-{
- $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
+else if ($action == 'setmode' && $user->rights->commande->creer) {
+ $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
if ($result < 0)
- {
- dol_print_error($db,$object->error);
- }
- else
- {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
+ dol_print_error($db, $object->error);
+}
+
+else if ($action == 'setavailability' && $user->rights->commande->creer) {
+ $result = $object->availability(GETPOST('availability_id'));
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+}
+
+else if ($action == 'setdemandreason' && $user->rights->commande->creer) {
+ $result = $object->demand_reason(GETPOST('demand_reason_id'));
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+}
+
+else if ($action == 'setconditions' && $user->rights->commande->creer) {
+ $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
+ if ($result < 0) {
+ dol_print_error($db, $object->error);
+ } else {
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;
- $newlang=GETPOST('lang_id','alpha');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = GETPOST('lang_id', 'alpha');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $ret=$object->fetch($object->id); // Reload to get new records
+
+ $ret = $object->fetch($object->id); // Reload to get new records
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
}
-}
+}
-else if ($action == 'setremisepercent' && $user->rights->commande->creer)
-{
+else if ($action == 'setremisepercent' && $user->rights->commande->creer) {
$result = $object->set_remise($user, GETPOST('remise_percent'));
-}
+}
-else if ($action == 'setremiseabsolue' && $user->rights->commande->creer)
-{
+else if ($action == 'setremiseabsolue' && $user->rights->commande->creer) {
$result = $object->set_remise_absolue($user, GETPOST('remise_absolue'));
-}
+}
// Add a new line
-else if ($action == 'addline' && $user->rights->commande->creer)
-{
+else if ($action == 'addline' && $user->rights->commande->creer) {
$langs->load('errors');
$error = false;
-
+
// Set if we used free entry or predefined product
- if (GETPOST('addline_libre'))
- {
- $predef='';
- $idprod=0;
- $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
+ if (GETPOST('addline_libre')) {
+ $predef = '';
+ $idprod = 0;
+ $product_desc = (GETPOST('dp_desc') ? GETPOST('dp_desc') : '');
$price_ht = GETPOST('price_ht');
- $tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
+ $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
}
- if (GETPOST('addline_predefined'))
- {
- $predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
- $idprod=GETPOST('idprod', 'int');
- $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):''));
+ if (GETPOST('addline_predefined')) {
+ $predef = (($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
+ $idprod = GETPOST('idprod', 'int');
+ $product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : ''));
$price_ht = '';
$tva_tx = '';
}
- if (GETPOST('usenewaddlineform')) {
- $idprod=GETPOST('idprod', 'int');
- $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):'')));
- $price_ht = GETPOST('price_ht');
- $tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
- }
- $qty = GETPOST('qty'.$predef);
- $remise_percent=GETPOST('remise_percent'.$predef);
-
- //Extrafields
+ if (GETPOST('usenewaddlineform')) {
+ $idprod = GETPOST('idprod', 'int');
+ $product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : (GETPOST('dp_desc') ? GETPOST('dp_desc') : '')));
+ $price_ht = GETPOST('price_ht');
+ $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
+ }
+ $qty = GETPOST('qty' . $predef);
+ $remise_percent = GETPOST('remise_percent' . $predef);
+
+ // Extrafields
$extrafieldsline = new ExtraFields($db);
- $extralabelsline =$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
- $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline,$predef);
- //Unset extrafield
- if (is_array($extralabelsline))
- {
+ $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+ $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
+ // Unset extrafield
+ if (is_array($extralabelsline)) {
// Get extra fields
- foreach ($extralabelsline as $key => $value)
- {
- unset($_POST["options_".$key]);
+ foreach ($extralabelsline as $key => $value) {
+ unset($_POST ["options_" . $key]);
}
}
-
- if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && ($qty < 0))
- {
+
+ if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && ($qty < 0)) {
setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
+ $error ++;
}
- if (empty($idprod) && GETPOST('type') < 0)
- {
+ if (empty($idprod) && GETPOST('type') < 0) {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
- $error++;
+ $error ++;
}
- if ((empty($idprod) || GETPOST('usenewaddlineform')) && (!($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not ''
+ if ((empty($idprod) || GETPOST('usenewaddlineform')) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not ''
{
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
- $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
+ $error ++;
}
- if ($qty == '')
- {
+ if ($qty == '') {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
+ $error ++;
}
- if (empty($idprod) && empty($product_desc))
- {
+ if (empty($idprod) && empty($product_desc)) {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
- $error++;
+ $error ++;
}
-
- if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod)))
- {
+
+ if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) {
// Clean parameters
- $date_start=dol_mktime(0, 0, 0, GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
- $date_end=dol_mktime(0, 0, 0, GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
- $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT');
-
+ $date_start = dol_mktime(0, 0, 0, GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
+ $date_end = dol_mktime(0, 0, 0, GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
+ $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
+
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
// Ecrase $base_price_type par celui du produit
- if (! empty($idprod))
- {
+ if (! empty($idprod)) {
$prod = new Product($db);
$prod->fetch($idprod);
-
- $label = ((GETPOST('product_label') && GETPOST('product_label')!=$prod->label)?GETPOST('product_label'):'');
-
+
+ $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
+
// Update if prices fields are defined
- if (GETPOST('usenewaddlineform'))
- {
- $pu_ht=price2num($price_ht, 'MU');
- $pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
- $tva_npr=(preg_match('/\*/', $tva_tx)?1:0);
- $tva_tx=str_replace('*','', $tva_tx);
+ if (GETPOST('usenewaddlineform')) {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
+ $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
+ $tva_tx = str_replace('*', '', $tva_tx);
$desc = $product_desc;
- }
- else
- {
- $tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
- $tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
-
+ } else {
+ $tva_tx = get_default_tva($mysoc, $object->client, $prod->id);
+ $tva_npr = get_default_npr($mysoc, $object->client, $prod->id);
+
// multiprix
- if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level))
- {
- $pu_ht = $prod->multiprices[$object->client->price_level];
- $pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
- $price_min = $prod->multiprices_min[$object->client->price_level];
- $price_base_type = $prod->multiprices_base_type[$object->client->price_level];
- }
- elseif (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
+ if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) {
+ $pu_ht = $prod->multiprices [$object->client->price_level];
+ $pu_ttc = $prod->multiprices_ttc [$object->client->price_level];
+ $price_min = $prod->multiprices_min [$object->client->price_level];
+ $price_base_type = $prod->multiprices_base_type [$object->client->price_level];
+ } elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
-
- $prodcustprice = new Productcustomerprice( $db );
-
- $filter = array (
- 't.fk_product' => $prod->id,
- 't.fk_soc'=> $object->client->id
- );
-
- $result = $prodcustprice->fetch_all( '', '', 0,0, $filter );
- if ($result)
- {
- if (count($prodcustprice->lines)>0)
- {
- $found=true;
- $pu_ht=price($prodcustprice->lines[0]->price);
- $pu_ttc=price($prodcustprice->lines[0]->price_ttc);
- $price_base_type=$prodcustprice->lines[0]->price_base_type;
- $prod->tva_tx=$prodcustprice->lines[0]->tva_tx;
+
+ $prodcustprice = new Productcustomerprice($db);
+
+ $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->client->id);
+
+ $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
+ if ($result) {
+ if (count($prodcustprice->lines) > 0) {
+ $found = true;
+ $pu_ht = price($prodcustprice->lines [0]->price);
+ $pu_ttc = price($prodcustprice->lines [0]->price_ttc);
+ $price_base_type = $prodcustprice->lines [0]->price_base_type;
+ $prod->tva_tx = $prodcustprice->lines [0]->tva_tx;
}
}
- }
- else
- {
+ } else {
$pu_ht = $prod->price;
$pu_ttc = $prod->price_ttc;
$price_min = $prod->price_min;
$price_base_type = $prod->price_base_type;
}
-
+
// if price ht is forced (ie: calculated by margin rate and cost price)
- if (!empty($price_ht))
- {
- $pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
- }
+ if (! empty($price_ht)) {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
+ }
// On reevalue prix selon taux tva car taux tva transaction peut etre different
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
- elseif ($tva_tx != $prod->tva_tx)
- {
- if ($price_base_type != 'HT')
- {
- $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
- }
- else
- {
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
+ elseif ($tva_tx != $prod->tva_tx) {
+ if ($price_base_type != 'HT') {
+ $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU');
+ } else {
+ $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
}
}
-
- $desc='';
-
+
+ $desc = '';
+
// Define output language
- if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
- {
+ if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
$outputlangs = $langs;
- $newlang='';
- if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if (empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if (empty($newlang) && GETPOST('lang_id'))
+ $newlang = GETPOST('lang_id');
+ if (empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $desc = (! empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
- }
- else
- {
+
+ $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
+ } else {
$desc = $prod->description;
}
-
- $desc=dol_concatdesc($desc,$product_desc);
-
+
+ $desc = dol_concatdesc($desc, $product_desc);
+
// Add custom code and origin country into description
- if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
- {
- $tmptxt='(';
- if (! empty($prod->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
- if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - ';
- if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0);
- $tmptxt.=')';
- $desc= dol_concatdesc($desc, $tmptxt);
+ if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
+ $tmptxt = '(';
+ if (! empty($prod->customcode))
+ $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
+ if (! empty($prod->customcode) && ! empty($prod->country_code))
+ $tmptxt .= ' - ';
+ if (! empty($prod->country_code))
+ $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
+ $tmptxt .= ')';
+ $desc = dol_concatdesc($desc, $tmptxt);
}
}
-
+
$type = $prod->type;
+ } else {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
+ $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
+ $tva_tx = str_replace('*', '', $tva_tx);
+ $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
+ $desc = $product_desc;
+ $type = GETPOST('type');
}
- else
- {
- $pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
- $tva_npr = (preg_match('/\*/', $tva_tx)?1:0);
- $tva_tx = str_replace('*', '', $tva_tx);
- $label = (GETPOST('product_label')?GETPOST('product_label'):'');
- $desc = $product_desc;
- $type = GETPOST('type');
- }
-
+
// Margin
- $fournprice=(GETPOST('fournprice'.$predef)?GETPOST('fournprice'.$predef):'');
- $buyingprice=(GETPOST('buying_price'.$predef)?GETPOST('buying_price'.$predef):'');
-
+ $fournprice = (GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
+ $buyingprice = (GETPOST('buying_price' . $predef) ? GETPOST('buying_price' . $predef) : '');
+
// Local Taxes
- $localtax1_tx= get_localtax($tva_tx, 1, $object->client);
- $localtax2_tx= get_localtax($tva_tx, 2, $object->client);
-
- $desc=dol_htmlcleanlastbr($desc);
-
- $info_bits=0;
- if ($tva_npr) $info_bits |= 0x01;
-
- if (! empty($price_min) && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min)))
- {
- $mesg = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency));
+ $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
+ $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
+
+ $desc = dol_htmlcleanlastbr($desc);
+
+ $info_bits = 0;
+ if ($tva_npr)
+ $info_bits |= 0x01;
+
+ if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) {
+ $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
setEventMessage($mesg, 'errors');
- }
- else
- {
+ } else {
// Insert line
- $result = $object->addline(
- $desc,
- $pu_ht,
- $qty,
- $tva_tx,
- $localtax1_tx,
- $localtax2_tx,
- $idprod,
- $remise_percent,
- $info_bits,
- 0,
- $price_base_type,
- $pu_ttc,
- $date_start,
- $date_end,
- $type,
- -1,
- 0,
- GETPOST('fk_parent_line'),
- $fournprice,
- $buyingprice,
- $label,
- $array_option
- );
-
- if ($result > 0)
- {
- $ret=$object->fetch($object->id); // Reload to get new records
-
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
+ $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_option);
+
+ if ($result > 0) {
+ $ret = $object->fetch($object->id); // Reload to get new records
+
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;
- $newlang=GETPOST('lang_id','alpha');
- if (! empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = GETPOST('lang_id', 'alpha');
+ if (! empty($conf->global->MAIN_MULTILANGS) && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
+
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
-
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['remise_percent']);
- unset($_POST['price_ht']);
- unset($_POST['price_ttc']);
- unset($_POST['tva_tx']);
- unset($_POST['product_ref']);
- unset($_POST['product_label']);
- unset($_POST['product_desc']);
- unset($_POST['fournprice']);
- unset($_POST['buying_price']);
- unset($_POST['np_marginRate']);
- unset($_POST['np_markRate']);
- unset($_POST['dp_desc']);
-
- unset($_POST['idprod']);
- unset($_POST['qty_predef']);
- unset($_POST['remise_percent_predef']);
- unset($_POST['fournprice_predef']);
- unset($_POST['buying_price_predef']);
- unset($_POST['np_marginRate_predef']);
- unset($_POST['np_markRate_predef']);
- unset($_POST['np_desc']);
- }
- else
- {
+
+ unset($_POST ['qty']);
+ unset($_POST ['type']);
+ unset($_POST ['remise_percent']);
+ unset($_POST ['price_ht']);
+ unset($_POST ['price_ttc']);
+ unset($_POST ['tva_tx']);
+ unset($_POST ['product_ref']);
+ unset($_POST ['product_label']);
+ unset($_POST ['product_desc']);
+ unset($_POST ['fournprice']);
+ unset($_POST ['buying_price']);
+ unset($_POST ['np_marginRate']);
+ unset($_POST ['np_markRate']);
+ unset($_POST ['dp_desc']);
+
+ unset($_POST ['idprod']);
+ unset($_POST ['qty_predef']);
+ unset($_POST ['remise_percent_predef']);
+ unset($_POST ['fournprice_predef']);
+ unset($_POST ['buying_price_predef']);
+ unset($_POST ['np_marginRate_predef']);
+ unset($_POST ['np_markRate_predef']);
+ unset($_POST ['np_desc']);
+ } else {
setEventMessage($object->error, 'errors');
}
}
}
-}
+}
/*
* Mise a jour d'une ligne dans la commande
*/
-else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST('save') == $langs->trans('Save'))
-{
+else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST('save') == $langs->trans('Save')) {
// Clean parameters
- $date_start='';
- $date_end='';
- $date_start=dol_mktime(0, 0, 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
- $date_end=dol_mktime(0, 0, 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
- $description=dol_htmlcleanlastbr(GETPOST('product_desc'));
- $pu_ht=GETPOST('price_ht');
- $vat_rate=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
-
+ $date_start = '';
+ $date_end = '';
+ $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
+ $date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
+ $description = dol_htmlcleanlastbr(GETPOST('product_desc'));
+ $pu_ht = GETPOST('price_ht');
+ $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
+
// Define info_bits
- $info_bits=0;
- if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01;
-
- // Define vat_rate
- $vat_rate=str_replace('*','',$vat_rate);
- $localtax1_rate=get_localtax($vat_rate,1,$object->client);
- $localtax2_rate=get_localtax($vat_rate,2,$object->client);
-
+ $info_bits = 0;
+ if (preg_match('/\*/', $vat_rate))
+ $info_bits |= 0x01;
+
+ // Define vat_rate
+ $vat_rate = str_replace('*', '', $vat_rate);
+ $localtax1_rate = get_localtax($vat_rate, 1, $object->client);
+ $localtax2_rate = get_localtax($vat_rate, 2, $object->client);
+
// Add buying price
- $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):'');
- $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):'');
-
- //Extrafields Lines
+ $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
+ $buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
+
+ // Extrafields Lines
$extrafieldsline = new ExtraFields($db);
- $extralabelsline =$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+ $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
- //Unset extrafield POST Data
- if (is_array($extralabelsline))
- {
- foreach ($extralabelsline as $key => $value)
- {
- unset($_POST["options_".$key]);
+ // Unset extrafield POST Data
+ if (is_array($extralabelsline)) {
+ foreach ($extralabelsline as $key => $value) {
+ unset($_POST ["options_" . $key]);
}
}
-
+
// Check minimum price
$productid = GETPOST('productid', 'int');
- if (! empty($productid))
- {
+ if (! empty($productid)) {
$product = new Product($db);
$product->fetch($productid);
-
- $type=$product->type;
-
+
+ $type = $product->type;
+
$price_min = $product->price_min;
if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level))
- $price_min = $product->multiprices_min[$object->client->price_level];
-
- $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label'):'');
-
- if ($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
- {
- setEventMessage($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)), 'errors');
- $error++;
+ $price_min = $product->multiprices_min [$object->client->price_level];
+
+ $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
+
+ if ($price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
+ setEventMessage($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), 'errors');
+ $error ++;
}
- }
- else
- {
+ } else {
$type = GETPOST('type');
- $label = (GETPOST('product_label') ? GETPOST('product_label'):'');
-
+ $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
+
// Check parameters
if (GETPOST('type') < 0) {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
- $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), 'errors');
+ $error ++;
}
}
-
- if (! $error)
- {
- $result = $object->updateline(
- GETPOST('lineid'),
- $description,
- $pu_ht,
- GETPOST('qty'),
- GETPOST('remise_percent'),
- $vat_rate,
- $localtax1_rate,
- $localtax2_rate,
- 'HT',
- $info_bits,
- $date_start,
- $date_end,
- $type,
- GETPOST('fk_parent_line'),
- 0,
- $fournprice,
- $buyingprice,
- $label,
- 0,
- $array_option
- );
-
- if ($result >= 0)
- {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
+
+ if (! $error) {
+ $result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, 0, $array_option);
+
+ if ($result >= 0) {
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
+ $newlang = GETPOST('lang_id');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $ret=$object->fetch($object->id); // Reload to get new records
+
+ $ret = $object->fetch($object->id); // Reload to get new records
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
-
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['productid']);
- unset($_POST['remise_percent']);
- unset($_POST['price_ht']);
- unset($_POST['price_ttc']);
- unset($_POST['tva_tx']);
- unset($_POST['product_ref']);
- unset($_POST['product_label']);
- unset($_POST['product_desc']);
- unset($_POST['fournprice']);
- unset($_POST['buying_price']);
- }
- else
- {
+
+ unset($_POST ['qty']);
+ unset($_POST ['type']);
+ unset($_POST ['productid']);
+ unset($_POST ['remise_percent']);
+ unset($_POST ['price_ht']);
+ unset($_POST ['price_ttc']);
+ unset($_POST ['tva_tx']);
+ unset($_POST ['product_ref']);
+ unset($_POST ['product_label']);
+ unset($_POST ['product_desc']);
+ unset($_POST ['fournprice']);
+ unset($_POST ['buying_price']);
+ } else {
setEventMessage($object->error, 'errors');
}
}
-}
+}
-else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST('cancel') == $langs->trans('Cancel'))
-{
- header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
- exit;
-}
-
-else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->commande->valider)
-{
- $idwarehouse=GETPOST('idwarehouse');
+else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST('cancel') == $langs->trans('Cancel')) {
+ header('Location: ' . $_SERVER ['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
+ exit();
+}
+else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->commande->valider) {
+ $idwarehouse = GETPOST('idwarehouse');
+
// Check parameters
- if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- $mesgs[]='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")).'
';
- $action='';
+ if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
+ if (! $idwarehouse || $idwarehouse == - 1) {
+ $error ++;
+ $mesgs [] = '
' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '
';
+ $action = '';
}
}
-
- if (! $error)
- {
- $result=$object->valid($user,$idwarehouse);
- if ($result >= 0)
- {
+
+ if (! $error) {
+ $result = $object->valid($user, $idwarehouse);
+ if ($result >= 0) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
- }
-}
-
-// Go back to draft status
-else if ($action == 'confirm_modif' && $user->rights->commande->creer)
-{
- $idwarehouse=GETPOST('idwarehouse');
-
- // Check parameters
- if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- $mesgs[]='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")).'
';
- $action='';
- }
- }
-
- if (! $error)
- {
- $result = $object->set_draft($user,$idwarehouse);
- if ($result >= 0)
- {
- // Define output language
- $outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $ret=$object->fetch($object->id); // Reload to get new records
+ commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ }
+ }
+}
+
+// Go back to draft status
+else if ($action == 'confirm_modif' && $user->rights->commande->creer) {
+ $idwarehouse = GETPOST('idwarehouse');
+
+ // Check parameters
+ if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
+ if (! $idwarehouse || $idwarehouse == - 1) {
+ $error ++;
+ $mesgs [] = '
' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '
';
+ $action = '';
+ }
+ }
+
+ if (! $error) {
+ $result = $object->set_draft($user, $idwarehouse);
+ if ($result >= 0) {
+ // Define output language
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $ret = $object->fetch($object->id); // Reload to get new records
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
}
}
-}
+}
-else if ($action == 'confirm_shipped' && $confirm == 'yes' && $user->rights->commande->cloturer)
-{
+else if ($action == 'confirm_shipped' && $confirm == 'yes' && $user->rights->commande->cloturer) {
$result = $object->cloture($user);
- if ($result < 0) $mesgs=$object->errors;
-}
-
-else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->commande->valider)
-{
- $idwarehouse=GETPOST('idwarehouse');
+ if ($result < 0)
+ $mesgs = $object->errors;
+}
+else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->commande->valider) {
+ $idwarehouse = GETPOST('idwarehouse');
+
// Check parameters
- if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- $mesgs[]='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")).'
';
- $action='';
+ if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
+ if (! $idwarehouse || $idwarehouse == - 1) {
+ $error ++;
+ $mesgs [] = '
' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '
';
+ $action = '';
}
}
-
- if (! $error)
- {
+
+ if (! $error) {
$result = $object->cancel($idwarehouse);
}
-}
-
+}
/*
* Ordonnancement des lignes
*/
-else if ($action == 'up' && $user->rights->commande->creer)
-{
+else if ($action == 'up' && $user->rights->commande->creer) {
$object->line_up(GETPOST('rowid'));
-
+
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
+
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+ commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?id=' . $object->id . '#' . GETPOST('rowid'));
+ exit();
+}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
-
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('rowid'));
- exit;
-}
-
-else if ($action == 'down' && $user->rights->commande->creer)
-{
+else if ($action == 'down' && $user->rights->commande->creer) {
$object->line_down(GETPOST('rowid'));
-
+
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+ commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?id=' . $object->id . '#' . GETPOST('rowid'));
+ exit();
+}
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('rowid'));
- exit;
-}
-
-else if ($action == 'builddoc') // In get or post
+else if ($action == 'builddoc') // In get or post
{
/*
* Generate order document
* define into /core/modules/commande/modules_commande.php
*/
-
+
// Save last template used to generate document
- if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
-
- // Define output language
+ if (GETPOST('model'))
+ $object->setDocModel($user, GETPOST('model', 'alpha'));
+
+ // Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- $result=commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
-
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
+ $result = commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+
+ if ($result <= 0) {
+ dol_print_error($db, $result);
+ exit();
}
-}
+}
// Remove file in doc form
-else if ($action == 'remove_file')
-{
- if ($object->id > 0)
- {
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+else if ($action == 'remove_file') {
+ if ($object->id > 0) {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
$langs->load("other");
$upload_dir = $conf->commande->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
- $ret=dol_delete_file($file,0,0,0,$object);
- if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
- else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
- $action='';
+ $ret = dol_delete_file($file, 0, 0, 0, $object);
+ if ($ret)
+ setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else
+ setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
+ $action = '';
}
-}
+}
// Print file
-else if ($action == 'print_file' AND $user->rights->printipp->read)
-{
- require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
- $printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD);
- $printer->print_file(GETPOST('file','alpha'),GETPOST('printer','alpha'));
- setEventMessage($langs->trans("FileWasSentToPrinter", GETPOST('file')));
- $action='';
-}
+else if ($action == 'print_file' and $user->rights->printipp->read) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/dolprintipp.class.php';
+ $printer = new dolPrintIPP($db, $conf->global->PRINTIPP_HOST, $conf->global->PRINTIPP_PORT, $user->login, $conf->global->PRINTIPP_USER, $conf->global->PRINTIPP_PASSWORD);
+ $printer->print_file(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha'));
+ setEventMessage($langs->trans("FileWasSentToPrinter", GETPOST('file')));
+ $action = '';
+}
-else if ($action == 'update_extras')
-{
+else if ($action == 'update_extras') {
// Fill array 'array_options' with data from update form
- $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
- if($ret < 0) $error++;
-
- if (! $error)
- {
+ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+ $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
+ if ($ret < 0)
+ $error ++;
+
+ if (! $error) {
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('orderdao'));
- $parameters=array('id'=>$object->id);
- $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
- if (empty($reshook))
- {
- $result=$object->insertExtraFields();
- if ($result < 0)
- {
- $error++;
+ $parameters = array('id' => $object->id);
+ $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by
+ // some hooks
+ if (empty($reshook)) {
+ $result = $object->insertExtraFields();
+ if ($result < 0) {
+ $error ++;
}
- }
- else if ($reshook < 0) $error++;
+ } else if ($reshook < 0)
+ $error ++;
}
-
- if ($error) $action = 'edit_extras';
+
+ if ($error)
+ $action = 'edit_extras';
}
/*
* Add file in email form
*/
-if (GETPOST('addfile'))
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+if (GETPOST('addfile')) {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
// Set tmp user directory TODO Use a dedicated directory for temp mails files
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir_tmp = $vardir.'/temp';
-
- dol_add_file_process($upload_dir_tmp,0,0);
- $action ='presend';
+ $vardir = $conf->user->dir_output . "/" . $user->id;
+ $upload_dir_tmp = $vardir . '/temp';
+
+ dol_add_file_process($upload_dir_tmp, 0, 0);
+ $action = 'presend';
}
/*
* Remove file in email form
*/
-if (GETPOST('removedfile'))
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+if (GETPOST('removedfile')) {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
// Set tmp user directory
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir_tmp = $vardir.'/temp';
-
+ $vardir = $conf->user->dir_output . "/" . $user->id;
+ $upload_dir_tmp = $vardir . '/temp';
+
// TODO Delete only files that was uploaded from email form
- dol_remove_file_process(GETPOST('removedfile'),0);
- $action ='presend';
+ dol_remove_file_process(GETPOST('removedfile'), 0);
+ $action = 'presend';
}
/*
* Send mail
*/
-if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
-{
+if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) {
$langs->load('mails');
-
- if ($object->id > 0)
- {
- // $ref = dol_sanitizeFileName($object->ref);
- // $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
-
- // if (is_readable($file))
- // {
- if (GETPOST('sendto'))
- {
+
+ if ($object->id > 0) {
+ // $ref = dol_sanitizeFileName($object->ref);
+ // $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+
+ // if (is_readable($file))
+ // {
+ if (GETPOST('sendto')) {
// Le destinataire a ete fourni via le champ libre
$sendto = GETPOST('sendto');
$sendtoid = 0;
- }
- elseif (GETPOST('receiver') != '-1')
- {
+ } elseif (GETPOST('receiver') != '-1') {
// Recipient was provided from combo list
- if (GETPOST('receiver') == 'thirdparty') // Id of third party
+ if (GETPOST('receiver') == 'thirdparty') // Id of third party
{
$sendto = $object->client->email;
$sendtoid = 0;
- }
- else // Id du contact
+ } else // Id du contact
{
- $sendto = $object->client->contact_get_property(GETPOST('receiver'),'email');
+ $sendto = $object->client->contact_get_property(GETPOST('receiver'), 'email');
$sendtoid = GETPOST('receiver');
}
}
-
- if (dol_strlen($sendto))
- {
+
+ if (dol_strlen($sendto)) {
$langs->load("commercial");
-
- $from = GETPOST('fromname') . ' <' . GETPOST('frommail') .'>';
- $replyto = GETPOST('replytoname'). ' <' . GETPOST('replytomail').'>';
+
+ $from = GETPOST('fromname') . ' <' . GETPOST('frommail') . '>';
+ $replyto = GETPOST('replytoname') . ' <' . GETPOST('replytomail') . '>';
$message = GETPOST('message');
$sendtocc = GETPOST('sendtocc');
$deliveryreceipt = GETPOST('deliveryreceipt');
-
- if ($action == 'send')
- {
- if (dol_strlen(GETPOST('subject'))) $subject=GETPOST('subject');
- else $subject = $langs->transnoentities('Order').' '.$object->ref;
- $actiontypecode='AC_COM';
- $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
- if ($message)
- {
- $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
- $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
- $actionmsg.=$message;
+
+ if ($action == 'send') {
+ if (dol_strlen(GETPOST('subject')))
+ $subject = GETPOST('subject');
+ else
+ $subject = $langs->transnoentities('Order') . ' ' . $object->ref;
+ $actiontypecode = 'AC_COM';
+ $actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto . ".\n";
+ if ($message) {
+ $actionmsg .= $langs->transnoentities('MailTopic') . ": " . $subject . "\n";
+ $actionmsg .= $langs->transnoentities('TextUsedInTheMessageBody') . ":\n";
+ $actionmsg .= $message;
}
- $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+ $actionmsg2 = $langs->transnoentities('Action' . $actiontypecode);
}
-
+
// Create form object
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
-
- $attachedfiles=$formmail->get_attached_files();
- $filepath = $attachedfiles['paths'];
- $filename = $attachedfiles['names'];
- $mimetype = $attachedfiles['mimes'];
-
+
+ $attachedfiles = $formmail->get_attached_files();
+ $filepath = $attachedfiles ['paths'];
+ $filename = $attachedfiles ['names'];
+ $mimetype = $attachedfiles ['mimes'];
+
// Send mail
- require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
- $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
- if ($mailfile->error)
- {
- $mesg='
'.$mailfile->error.'
';
- }
- else
- {
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contains "
-
- $error=0;
-
+ require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
+ $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, - 1);
+ if ($mailfile->error) {
+ $mesg = '
' . $mailfile->error . '
';
+ } else {
+ $result = $mailfile->sendfile();
+ if ($result) {
+ $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)); // Must not
+ // contains "
+
+ $error = 0;
+
// Initialisation donnees
- $object->sendtoid = $sendtoid;
- $object->actiontypecode = $actiontypecode;
- $object->actionmsg = $actionmsg;
- $object->actionmsg2 = $actionmsg2;
- $object->fk_element = $object->id;
- $object->elementtype = $object->element;
-
+ $object->sendtoid = $sendtoid;
+ $object->actiontypecode = $actiontypecode;
+ $object->actionmsg = $actionmsg;
+ $object->actionmsg2 = $actionmsg2;
+ $object->fk_element = $object->id;
+ $object->elementtype = $object->element;
+
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
- $interface=new Interfaces($db);
- $result=$interface->run_triggers('ORDER_SENTBYMAIL',$object,$user,$langs,$conf);
+ $interface = new Interfaces($db);
+ $result = $interface->run_triggers('ORDER_SENTBYMAIL', $object, $user, $langs, $conf);
if ($result < 0) {
- $error++; $this->errors=$interface->errors;
+ $error ++;
+ $this->errors = $interface->errors;
}
// Fin appel triggers
-
- if ($error)
- {
+
+ if ($error) {
dol_print_error($db);
- }
- else
- {
+ } else {
// Redirect here
// This avoid sending mail twice if going out and then back to page
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg));
- exit;
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?id=' . $object->id . '&mesg=' . urlencode($mesg));
+ exit();
}
- }
- else
- {
+ } else {
$langs->load("other");
- $mesg='
';
- if ($mailfile->error)
- {
- $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
- $mesg.='
'.$mailfile->error;
+ $mesg = '
';
+ if ($mailfile->error) {
+ $mesg .= $langs->trans('ErrorFailedToSendMail', $from, $sendto);
+ $mesg .= ' ' . $mailfile->error;
+ } else {
+ $mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
}
- else
- {
- $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
- }
- $mesg.='
';
+ $mesg .= '
';
}
}
/* }
@@ -1410,1303 +1205,1178 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
$action='presend';
dol_syslog('Recipient email is empty');
}*/
- }
- else
- {
+ } else {
$langs->load("errors");
- $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
';
- dol_syslog('Failed to read file: '.$file);
+ $mesg = '
' . $langs->trans('ErrorCantReadFile', $file) . '
';
+ dol_syslog('Failed to read file: ' . $file);
}
- }
- else
- {
+ } else {
$langs->load("other");
- $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Order")).'
';
+ $mesg = '
' . $langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")) . '
';
dol_syslog($langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")));
}
}
-if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer)
-{
- if ($action == 'addcontact')
- {
- if ($object->id > 0)
- {
+if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer) {
+ if ($action == 'addcontact') {
+ if ($object->id > 0) {
$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
$result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source'));
}
-
- if ($result >= 0)
- {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- }
- else
- {
- if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
+
+ if ($result >= 0) {
+ header("Location: " . $_SERVER ['PHP_SELF'] . "?id=" . $object->id);
+ exit();
+ } else {
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
- $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
';
- }
- else
- {
- $mesg = '
'.$object->error.'
';
+ $mesg = '
' . $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType") . '
';
+ } else {
+ $mesg = '
' . $object->error . '
';
}
}
- }
+ }
// bascule du statut d'un contact
- else if ($action == 'swapstatut')
- {
- if ($object->id > 0)
- {
- $result=$object->swapContactStatus(GETPOST('ligne'));
- }
- else
- {
+ else if ($action == 'swapstatut') {
+ if ($object->id > 0) {
+ $result = $object->swapContactStatus(GETPOST('ligne'));
+ } else {
dol_print_error($db);
}
- }
+ }
// Efface un contact
- else if ($action == 'deletecontact')
- {
+ else if ($action == 'deletecontact') {
$result = $object->delete_contact($lineid);
-
- if ($result >= 0)
- {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- }
- else {
+
+ if ($result >= 0) {
+ header("Location: " . $_SERVER ['PHP_SELF'] . "?id=" . $object->id);
+ exit();
+ } else {
dol_print_error($db);
}
}
}
-
/*
* View
*/
-llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
+llxHeader('', $langs->trans('Order'), 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
$form = new Form($db);
$formfile = new FormFile($db);
$formorder = new FormOrder($db);
-
-/*********************************************************************
+/**
+ * *******************************************************************
*
* Mode creation
*
- *********************************************************************/
-if ($action == 'create' && $user->rights->commande->creer)
-{
+ * *******************************************************************
+ */
+if ($action == 'create' && $user->rights->commande->creer) {
print_fiche_titre($langs->trans('CreateOrder'));
-
- dol_htmloutput_mesg($mesg,$mesgs,'error');
-
+
+ dol_htmloutput_mesg($mesg, $mesgs, 'error');
+
$soc = new Societe($db);
- if ($socid>0) $res=$soc->fetch($socid);
-
- if (! empty($origin) && ! empty($originid))
- {
+ if ($socid > 0)
+ $res = $soc->fetch($socid);
+
+ if (! empty($origin) && ! empty($originid)) {
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin;
- if (preg_match('/^([^_]+)_([^_]+)/i',$origin,$regs))
- {
- $element = $regs[1];
- $subelement = $regs[2];
+ if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
+ $element = $regs [1];
+ $subelement = $regs [2];
}
-
- if ($element == 'project')
- {
- $projectid=$originid;
- }
- else
- {
+
+ if ($element == 'project') {
+ $projectid = $originid;
+ } else {
// For compatibility
- if ($element == 'order' || $element == 'commande') {
+ if ($element == 'order' || $element == 'commande') {
$element = $subelement = 'commande';
}
- if ($element == 'propal') {
- $element = 'comm/propal'; $subelement = 'propal';
+ if ($element == 'propal') {
+ $element = 'comm/propal';
+ $subelement = 'propal';
}
if ($element == 'contract') {
$element = $subelement = 'contrat';
}
-
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
-
+
+ dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
+
$classname = ucfirst($subelement);
$objectsrc = new $classname($db);
$objectsrc->fetch($originid);
- if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines();
+ if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
+ $objectsrc->fetch_lines();
$objectsrc->fetch_thirdparty();
-
- //Replicate extrafields
+
+ // Replicate extrafields
$objectsrc->fetch_optionals($originid);
- $object->array_options=$objectsrc->array_options;
-
- $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
- $ref_client = (!empty($objectsrc->ref_client)?$objectsrc->ref_client:'');
-
+ $object->array_options = $objectsrc->array_options;
+
+ $projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
+ $ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
+
$soc = $objectsrc->client;
- $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
- $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
- $availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0));
- $demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0));
- $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
- $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
- $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
-
- $datedelivery = (!empty($objectsrc->date_livraison)?$objectsrc->date_livraison:'');
-
- $note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
- $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
-
+ $cond_reglement_id = (! empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (! empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
+ $mode_reglement_id = (! empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (! empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
+ $availability_id = (! empty($objectsrc->availability_id) ? $objectsrc->availability_id : (! empty($soc->availability_id) ? $soc->availability_id : 0));
+ $demand_reason_id = (! empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (! empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
+ $remise_percent = (! empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (! empty($soc->remise_percent) ? $soc->remise_percent : 0));
+ $remise_absolue = (! empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (! empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
+ $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : 0;
+
+ $datedelivery = (! empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : '');
+
+ $note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
+ $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
+
// Object source contacts list
- $srccontactslist = $objectsrc->liste_contact(-1,'external',1);
+ $srccontactslist = $objectsrc->liste_contact(- 1, 'external', 1);
}
+ } else {
+ $cond_reglement_id = $soc->cond_reglement_id;
+ $mode_reglement_id = $soc->mode_reglement_id;
+ $availability_id = $soc->availability_id;
+ $demand_reason_id = $soc->demand_reason_id;
+ $remise_percent = $soc->remise_percent;
+ $remise_absolue = 0;
+ $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : 0;
+ $projectid = 0;
}
- else
- {
- $cond_reglement_id = $soc->cond_reglement_id;
- $mode_reglement_id = $soc->mode_reglement_id;
- $availability_id = $soc->availability_id;
- $demand_reason_id = $soc->demand_reason_id;
- $remise_percent = $soc->remise_percent;
- $remise_absolue = 0;
- $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
- $projectid = 0;
- }
- $absolute_discount=$soc->getAvailableDiscounts();
-
-
-
- $nbrow=10;
-
- print '
';
-
-
+
// Show origin lines
- if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
- {
- $title=$langs->trans('ProductsAndServices');
+ if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
+ $title = $langs->trans('ProductsAndServices');
print_titre($title);
-
+
print '
';
-
+
$objectsrc->printOriginLinesList();
-
+
print '
';
}
-
-}
-else
-{
+} else {
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
- $now=dol_now();
-
- if ($object->id > 0)
- {
- dol_htmloutput_mesg($mesg,$mesgs);
-
- $product_static=new Product($db);
-
+ $now = dol_now();
+
+ if ($object->id > 0) {
+ dol_htmloutput_mesg($mesg, $mesgs);
+
+ $product_static = new Product($db);
+
$soc = new Societe($db);
$soc->fetch($object->socid);
-
+
$author = new User($db);
$author->fetch($object->user_author_id);
-
+
$head = commande_prepare_head($object);
dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), 0, 'order');
-
- $formconfirm='';
-
+
+ $formconfirm = '';
+
/*
* Confirmation de la suppression de la commande
*/
- if ($action == 'delete')
- {
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
+ if ($action == 'delete') {
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
}
-
+
/*
* Confirmation de la validation
*/
- if ($action == 'validate')
- {
+ if ($action == 'validate') {
// on verifie si l'objet est en numerotation provisoire
$ref = substr($object->ref, 1, 4);
- if ($ref == 'PROV')
- {
+ if ($ref == 'PROV') {
$numref = $object->getNextNumRef($soc);
- }
- else
- {
+ } else {
$numref = $object->ref;
}
-
- $text=$langs->trans('ConfirmValidateOrder',$numref);
- if (! empty($conf->notification->enabled))
- {
- require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
- $notify=new Notify($db);
- $text.='
';
- $text.=$notify->confirmMessage('ORDER_VALIDATE',$object->socid);
+
+ $text = $langs->trans('ConfirmValidateOrder', $numref);
+ if (! empty($conf->notification->enabled)) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
+ $notify = new Notify($db);
+ $text .= '
';
+ $text .= $notify->confirmMessage('ORDER_VALIDATE', $object->socid);
}
- $formquestion=array();
- if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
- {
+ $formquestion = array();
+ if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
$langs->load("stocks");
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- $formproduct=new FormProduct($db);
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
+ require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
+ $formproduct = new FormProduct($db);
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value'
+ // => 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"),
+ // 'value' => 1),
+ array('type' => 'other','name' => 'idwarehouse','label' => $langs->trans("SelectWarehouseForStockDecrease"),'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
}
-
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
+
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
}
-
+
// Confirm back to draft status
- if ($action == 'modif')
- {
- $text=$langs->trans('ConfirmUnvalidateOrder',$object->ref);
- $formquestion=array();
- if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
- {
+ if ($action == 'modif') {
+ $text = $langs->trans('ConfirmUnvalidateOrder', $object->ref);
+ $formquestion = array();
+ if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
$langs->load("stocks");
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- $formproduct=new FormProduct($db);
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
+ require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
+ $formproduct = new FormProduct($db);
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value'
+ // => 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"),
+ // 'value' => 1),
+ array('type' => 'other','name' => 'idwarehouse','label' => $langs->trans("SelectWarehouseForStockIncrease"),'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
}
-
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
+
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
}
-
-
+
/*
* Confirmation de la cloture
*/
- if ($action == 'shipped')
- {
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
+ if ($action == 'shipped') {
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
}
-
+
/*
* Confirmation de l'annulation
*/
- if ($action == 'cancel')
- {
- $text=$langs->trans('ConfirmCancelOrder',$object->ref);
- $formquestion=array();
- if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
- {
+ if ($action == 'cancel') {
+ $text = $langs->trans('ConfirmCancelOrder', $object->ref);
+ $formquestion = array();
+ if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
$langs->load("stocks");
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- $formproduct=new FormProduct($db);
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
+ require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
+ $formproduct = new FormProduct($db);
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value'
+ // => 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"),
+ // 'value' => 1),
+ array('type' => 'other','name' => 'idwarehouse','label' => $langs->trans("SelectWarehouseForStockIncrease"),'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
}
-
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Cancel'), $text, 'confirm_cancel', $formquestion, 0, 1);
+
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Cancel'), $text, 'confirm_cancel', $formquestion, 0, 1);
}
-
+
/*
* Confirmation de la suppression d'une ligne produit
*/
- if ($action == 'ask_deleteline')
- {
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
+ if ($action == 'ask_deleteline') {
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
}
-
+
// Clone confirmation
- if ($action == 'clone')
- {
+ if ($action == 'clone') {
// Create an array for form
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=3)'))
- );
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
+ // 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
+ // => 1),
+ array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=3)')));
// Paiement incomplet. On demande si motif = escompte ou autre
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneOrder'), $langs->trans('ConfirmCloneOrder', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
}
-
- if (! $formconfirm)
- {
- $parameters=array('lineid'=>$lineid);
- $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+
+ if (! $formconfirm) {
+ $parameters = array('lineid' => $lineid);
+ $formconfirm = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified
+ // by hook
}
-
+
// Print form confirm
print $formconfirm;
-
+
/*
* Commande
*/
- $nbrow=9;
- if (! empty($conf->projet->enabled)) $nbrow++;
-
- //Local taxes
- if($mysoc->localtax1_assuj=="1") $nbrow++;
- if($mysoc->localtax2_assuj=="1") $nbrow++;
-
+ $nbrow = 9;
+ if (! empty($conf->projet->enabled))
+ $nbrow ++;
+
+ // Local taxes
+ if ($mysoc->localtax1_assuj == "1")
+ $nbrow ++;
+ if ($mysoc->localtax2_assuj == "1")
+ $nbrow ++;
+
print '
';
-
- $linkback = ''.$langs->trans("BackToList").' ';
-
+
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
// Ref
- print ''.$langs->trans('Ref').' ';
+ print '' . $langs->trans('Ref') . ' ';
print '';
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
print ' ';
print ' ';
-
+
// Ref commande client
print '';
print '';
print ' ';
- if ($user->rights->commande->creer && $action == 'refcustomer')
- {
- print 'id.'" method="post">';
- print ' ';
+ if ($user->rights->commande->creer && $action == 'refcustomer') {
+ print ' id . '" method="post">';
+ print ' ';
print ' ';
- print ' ';
- print ' ';
+ print ' ';
+ print ' ';
print ' ';
- }
- else
- {
+ } else {
print $object->ref_client;
}
print ' ';
print ' ';
-
-
+
// Third party
- print ''.$langs->trans('Company').' ';
- print ''.$soc->getNomUrl(1).' ';
+ print '' . $langs->trans('Company') . ' ';
+ print '' . $soc->getNomUrl(1) . ' ';
print ' ';
-
- if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
- {
- $filterabsolutediscount="fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
- $filtercreditnote="fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
+
+ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
+ $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final
+ // invoice
+ $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
+ } else {
+ $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
+ $filtercreditnote = "fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
}
- else
- {
- $filterabsolutediscount="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
- $filtercreditnote="fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
- }
-
+
// Relative and absolute discounts
- $addrelativediscount='id.'">'.$langs->trans("EditRelativeDiscounts").' ';
- $addabsolutediscount='id.'">'.$langs->trans("EditGlobalDiscounts").' ';
- $addcreditnote='id.'">'.$langs->trans("AddCreditNote").' ';
-
- print ''.$langs->trans('Discounts').' ';
- if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_percent);
- else print $langs->trans("CompanyHasNoRelativeDiscount");
+ $addrelativediscount = 'id . '">' . $langs->trans("EditRelativeDiscounts") . ' ';
+ $addabsolutediscount = 'id . '">' . $langs->trans("EditGlobalDiscounts") . ' ';
+ $addcreditnote = 'id . '">' . $langs->trans("AddCreditNote") . ' ';
+
+ print ' ' . $langs->trans('Discounts') . ' ';
+ if ($soc->remise_percent)
+ print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
+ else
+ print $langs->trans("CompanyHasNoRelativeDiscount");
print '. ';
- $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
- $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
- $absolute_discount=price2num($absolute_discount,'MT');
- $absolute_creditnote=price2num($absolute_creditnote,'MT');
- if ($absolute_discount)
- {
- if ($object->statut > 0)
- {
- print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
- }
- else
- {
+ $absolute_discount = $soc->getAvailableDiscounts('', 'fk_facture_source IS NULL');
+ $absolute_creditnote = $soc->getAvailableDiscounts('', 'fk_facture_source IS NOT NULL');
+ $absolute_discount = price2num($absolute_discount, 'MT');
+ $absolute_creditnote = price2num($absolute_creditnote, 'MT');
+ if ($absolute_discount) {
+ if ($object->statut > 0) {
+ print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
+ } else {
// Remise dispo de type remise fixe (not credit note)
print ' ';
- $form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filterabsolutediscount);
+ $form->form_remise_dispo($_SERVER ["PHP_SELF"] . '?id=' . $object->id, 0, 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount);
}
}
- if ($absolute_creditnote)
- {
- print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. ';
+ if ($absolute_creditnote) {
+ print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '. ';
}
- if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
+ if (! $absolute_discount && ! $absolute_creditnote)
+ print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.';
print ' ';
-
+
// Date
print '';
print '';
print ' ';
- if ($action == 'editdate')
- {
- print 'id.'" method="post">';
- print ' ';
+ if ($action == 'editdate') {
+ print ' id . '" method="post">';
+ print ' ';
print ' ';
- $form->select_date($object->date,'order_','','','',"setdate");
- print ' ';
+ $form->select_date($object->date, 'order_', '', '', '', "setdate");
+ print ' ';
print ' ';
- }
- else
- {
- print $object->date ? dol_print_date($object->date,'daytext') : ' ';
+ } else {
+ print $object->date ? dol_print_date($object->date, 'daytext') : ' ';
}
print ' ';
print ' ';
-
+
// Delivery date planed
print '';
print '';
print ' ';
- if ($action == 'editdate_livraison')
- {
- print 'id.'" method="post">';
- print ' ';
+ if ($action == 'editdate_livraison') {
+ print ' id . '" method="post">';
+ print ' ';
print ' ';
- $form->select_date($object->date_livraison?$object->date_livraison:-1,'liv_','','','',"setdate_livraison");
- print ' ';
+ $form->select_date($object->date_livraison ? $object->date_livraison : - 1, 'liv_', '', '', '', "setdate_livraison");
+ print ' ';
print ' ';
- }
- else
- {
- print $object->date_livraison ? dol_print_date($object->date_livraison,'daytext') : ' ';
+ } else {
+ print $object->date_livraison ? dol_print_date($object->date_livraison, 'daytext') : ' ';
}
print ' ';
print ' ';
-
+
// Terms of payment
print '';
print '';
print ' ';
- if ($action == 'editconditions')
- {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id',1);
- }
- else
- {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none',1);
+ if ($action == 'editconditions') {
+ $form->form_conditions_reglement($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
+ } else {
+ $form->form_conditions_reglement($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'none', 1);
}
print ' ';
-
+
print ' ';
-
+
// Mode of payment
print '';
print '';
print ' ';
- if ($action == 'editmode')
- {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
- }
- else
- {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
+ if ($action == 'editmode') {
+ $form->form_modes_reglement($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id');
+ } else {
+ $form->form_modes_reglement($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none');
}
print ' ';
-
+
// Availability
print '';
print '';
print ' ';
- if ($action == 'editavailability')
- {
- $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1);
- }
- else
- {
- $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1);
+ if ($action == 'editavailability') {
+ $form->form_availability($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'availability_id', 1);
+ } else {
+ $form->form_availability($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'none', 1);
}
print ' ';
-
+
// Source
print '';
print '';
print ' ';
- if ($action == 'editdemandreason')
- {
- $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1);
- }
- else
- {
- $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none');
+ if ($action == 'editdemandreason') {
+ $form->form_demand_reason($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'demand_reason_id', 1);
+ } else {
+ $form->form_demand_reason($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'none');
}
// Removed because using dictionary is an admin feature, not a user feature. Ther is already the "star" to show info to admin users.
// This is to avoid too heavy screens and have an uniform look and feel for all screens.
- //print ' ';
- //print ''.$langs->trans("DictionarySource").' ';
+ // print ' ';
+ // print ''.$langs->trans("DictionarySource").' ';
print ' ';
-
+
// Project
- if (! empty($conf->projet->enabled))
- {
+ if (! empty($conf->projet->enabled)) {
$langs->load('projects');
print '';
print '';
print ' ';
- //print "$object->id, $object->socid, $object->fk_project";
- if ($action == 'classify')
- {
- $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid');
- }
- else
- {
- $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
+ // print "$object->id, $object->socid, $object->fk_project";
+ if ($action == 'classify') {
+ $form->form_project($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid');
+ } else {
+ $form->form_project($_SERVER ['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none');
}
print ' ';
}
-
-
- if ($soc->outstanding_limit)
- {
+
+ if ($soc->outstanding_limit) {
// Outstanding Bill
print '';
print $langs->trans('OutstandingBill');
print ' ';
- print price($soc->get_OutstandingBill()).' / ';
- print price($soc->outstanding_limit, 0, '', 1, -1, -1, $conf->currency);
+ print price($soc->get_OutstandingBill()) . ' / ';
+ print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
print ' ';
print ' ';
}
-
- // Other attributes (TODO Move this into an include)
- $res=$object->fetch_optionals($object->id,$extralabels);
- $parameters=array('colspan' => ' colspan="3"');
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook) && ! empty($extrafields->attribute_label))
- {
- foreach($extrafields->attribute_label as $key=>$label)
- {
+
+ // Other attributes (TODO Move this into an include)
+ $res = $object->fetch_optionals($object->id, $extralabels);
+ $parameters = array('colspan' => ' colspan="3"');
+ $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
+ // hook
+ if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+ foreach ($extrafields->attribute_label as $key => $label) {
if ($action == 'edit_extras') {
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
+ $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
} else {
- $value=$object->array_options["options_".$key];
+ $value = $object->array_options ["options_" . $key];
}
- if ($extrafields->attribute_type[$key] == 'separate')
- {
+ if ($extrafields->attribute_type [$key] == 'separate') {
print $extrafields->showSeparator($key);
- }
- else
- {
+ } else {
print 'attribute_required[$key])) print ' class="fieldrequired"';
- print '>'.$label.' ';
+ if (! empty($extrafields->attribute_required [$key]))
+ print ' class="fieldrequired"';
+ print '>' . $label . ' ';
// Convert date into timestamp format
- if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
- {
- $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]);
+ if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) {
+ $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]);
}
-
- if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key)
- {
- print '';
+
+ if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) {
+ print ' ';
print ' ';
- print ' ';
- print ' ';
- print ' ';
-
- print $extrafields->showInputField($key,$value);
-
- print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+
+ print $extrafields->showInputField($key, $value);
+
+ print ' ';
print ' ';
+ } else {
+ print $extrafields->showOutputField($key, $value);
+ if ($object->statut == 0 && $user->rights->commande->creer)
+ print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ' ';
}
- else
- {
- print $extrafields->showOutputField($key,$value);
- if ($object->statut == 0 && $user->rights->commande->creer) print ''.img_picto('','edit').' '.$langs->trans('Modify').' ';
- }
- print ' '."\n";
+ print '' . "\n";
}
}
}
-
- $rowspan=4;
- if ($mysoc->localtax1_assuj=="1") $rowspan++;
- if ($mysoc->localtax2_assuj=="1") $rowspan++;
-
- // Total HT
- print ''.$langs->trans('AmountHT').' ';
- print ''.price($object->total_ht,1,'',1,-1,-1,$conf->currency).' ';
-
+
+ $rowspan = 4;
+ if ($mysoc->localtax1_assuj == "1")
+ $rowspan ++;
+ if ($mysoc->localtax2_assuj == "1")
+ $rowspan ++;
+
+ // Total HT
+ print '' . $langs->trans('AmountHT') . ' ';
+ print '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
+
// Margin Infos
- if (! empty($conf->margin->enabled))
- {
- print '';
+ if (! empty($conf->margin->enabled)) {
+ print ' ';
$object->displayMarginInfos();
print ' ';
- }
- else print ' ';
-
+ } else
+ print ' ';
+
print ' ';
-
+
// Total TVA
- print ''.$langs->trans('AmountVAT').' '.price($object->total_tva,1,'',1,-1,-1,$conf->currency).' ';
-
+ print '' . $langs->trans('AmountVAT') . ' ' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
+
// Amount Local Taxes
- if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
+ if ($mysoc->localtax1_assuj == "1") // Localtax1 RE
{
- print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).' ';
- print ''.price($object->total_localtax1,1,'',1,-1,-1,$conf->currency).' ';
+ print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . ' ';
+ print '' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
}
- if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
+ if ($mysoc->localtax2_assuj == "1") // Localtax2 IRPF
{
- print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).' ';
- print ''.price($object->total_localtax2,1,'',1,-1,-1,$conf->currency).' ';
+ print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ' ';
+ print '' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
}
-
+
// Total TTC
- print ''.$langs->trans('AmountTTC').' '.price($object->total_ttc,1,'',1,-1,-1,$conf->currency).' ';
-
+ print '' . $langs->trans('AmountTTC') . ' ' . price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
+
// Statut
- print ''.$langs->trans('Status').' '.$object->getLibStatut(4).' ';
-
+ print '' . $langs->trans('Status') . ' ' . $object->getLibStatut(4) . ' ';
+
print '
';
print "\n";
-
- if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
- {
+
+ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
$blocname = 'contacts';
$title = $langs->trans('ContactsAddresses');
- include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+ include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
}
-
- if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
- {
+
+ if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
$blocname = 'notes';
$title = $langs->trans('Notes');
- include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+ include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
}
-
+
/*
* Lines
*/
$result = $object->getLinesArray();
-
-
- print '
id.(($action != 'editline')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
-
-
+
+ print ' id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
+
+
-
+
';
-
-
- if (! empty($conf->use_javascript_ajax) && $object->statut == 0)
- {
- include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
+
+ if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
+ include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
}
-
+
print '';
-
+
// Show object lines
if (! empty($object->lines))
- $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1);
-
+ $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
+
$numlines = count($object->lines);
-
+
/*
* Form to add new line
*/
- if ($object->statut == 0 && $user->rights->commande->creer)
- {
- if ($action != 'editline')
- {
- $var=true;
-
- if ($conf->global->MAIN_FEATURES_LEVEL > 1)
- {
+ if ($object->statut == 0 && $user->rights->commande->creer) {
+ if ($action != 'editline') {
+ $var = true;
+
+ if ($conf->global->MAIN_FEATURES_LEVEL > 1) {
// Add free or predefined products/services
- $object->formAddObjectLine(1,$mysoc,$soc);
- }
- else
- {
+ $object->formAddObjectLine(1, $mysoc, $soc);
+ } else {
// Add free products/services
- $object->formAddFreeProduct(1,$mysoc,$soc);
-
+ $object->formAddFreeProduct(1, $mysoc, $soc);
+
// Add predefined products/services
- if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
- {
- $var=!$var;
- $object->formAddPredefinedProduct(1,$mysoc,$soc);
+ if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) {
+ $var = ! $var;
+ $object->formAddPredefinedProduct(1, $mysoc, $soc);
}
}
-
- $parameters=array();
- $reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified by hook
}
}
print '
';
-
+
print " \n";
-
+
dol_fiche_end();
-
-
+
/*
* Boutons actions
*/
- if ($action != 'presend' && $action != 'editline')
- {
+ if ($action != 'presend' && $action != 'editline') {
print '
';
-
- $parameters=array();
- $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook))
- {
+
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified by hook
+ if (empty($reshook)) {
// Valid
- if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider)
- {
- print '
';
+ if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider) {
+ print '
';
}
// Edit
- if ($object->statut == 1 && $user->rights->commande->creer)
- {
- print '
';
+ if ($object->statut == 1 && $user->rights->commande->creer) {
+ print '
';
}
// 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.
+ 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.
{
- print '
'.$langs->trans("AddAction").' ';
+ print '
' . $langs->trans("AddAction") . ' ';
}
// Send
- if ($object->statut > 0)
- {
- if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send))
- {
- print '
';
- }
- else print '
';
+ if ($object->statut > 0) {
+ if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) {
+ print '
';
+ } else
+ print '
';
}
-
+
// Ship
- $numshipping=0;
- if (! empty($conf->expedition->enabled))
- {
+ $numshipping = 0;
+ if (! empty($conf->expedition->enabled)) {
$numshipping = $object->nb_expedition();
-
- if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0)
- {
- if (($conf->expedition_bon->enabled && $user->rights->expedition->creer)
- || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer))
- {
- if ($user->rights->expedition->creer)
- {
- print '
';
+
+ if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0) {
+ if (($conf->expedition_bon->enabled && $user->rights->expedition->creer) || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)) {
+ if ($user->rights->expedition->creer) {
+ print '
';
+ } else {
+ print '
';
}
- else
- {
- print '
';
- }
- }
- else
- {
+ } else {
$langs->load("errors");
- print '
';
+ print '
';
}
}
}
-
+
// Create intervention
- if ($conf->ficheinter->enabled)
- {
+ if ($conf->ficheinter->enabled) {
$langs->load("interventions");
-
- if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfServicesLines() > 0)
- {
- if ($user->rights->ficheinter->creer)
- {
- print '
';
- }
- else
- {
- print '
';
+
+ if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfServicesLines() > 0) {
+ if ($user->rights->ficheinter->creer) {
+ print '
';
+ } else {
+ print '
';
}
}
}
-
+
// Reopen a closed order
- if ($object->statut == 3 && $user->rights->commande->creer)
- {
- print '
';
+ if ($object->statut == 3 && $user->rights->commande->creer) {
+ print '
';
}
-
+
// Create contract
- if ($conf->contrat->enabled && ($object->statut == 1 || $object->statut == 2))
- {
+ if ($conf->contrat->enabled && ($object->statut == 1 || $object->statut == 2)) {
$langs->load("contracts");
-
- if ($user->rights->contrat->creer)
- {
- print '
';
+
+ if ($user->rights->contrat->creer) {
+ print '
';
}
}
-
+
// Create bill and Classify billed
// Note: Even if module invoice is not enabled, we should be able to use button "Classified billed"
- if ($object->statut > 0 && ! $object->billed)
- {
- if (! empty($conf->facture->enabled) && $user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER))
- {
- print '
';
+ if ($object->statut > 0 && ! $object->billed) {
+ if (! empty($conf->facture->enabled) && $user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
+ print '
';
}
- if ($user->rights->commande->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))
- {
- print '
';
+ if ($user->rights->commande->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
+ print '
';
}
}
-
+
// Set to shipped
- if (($object->statut == 1 || $object->statut == 2) && $user->rights->commande->cloturer)
- {
- print '
';
+ if (($object->statut == 1 || $object->statut == 2) && $user->rights->commande->cloturer) {
+ print '
';
}
-
+
// Clone
- if ($user->rights->commande->creer)
- {
- print '
';
+ if ($user->rights->commande->creer) {
+ print '
';
}
-
+
// Cancel order
- if ($object->statut == 1 && $user->rights->commande->annuler)
- {
- print '
';
+ if ($object->statut == 1 && $user->rights->commande->annuler) {
+ print '
';
}
-
+
// Delete order
- if ($user->rights->commande->supprimer)
- {
- if ($numshipping == 0)
- {
- print '
';
- }
- else
- {
- print '
';
+ if ($user->rights->commande->supprimer) {
+ if ($numshipping == 0) {
+ print '
';
+ } else {
+ print '
';
}
}
}
print '
';
}
print '
';
-
-
- if ($action != 'presend')
- {
+
+ if ($action != 'presend') {
print '
';
- //print '
';
- //print ' '; // ancre
-
+ // print '';
+ // print ' '; // ancre
+
/*
* Documents generes
*/
$comref = dol_sanitizeFileName($object->ref);
$file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
- $relativepath = $comref.'/'.$comref.'.pdf';
+ $relativepath = $comref . '/' . $comref . '.pdf';
$filedir = $conf->commande->dir_output . '/' . $comref;
- $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
- $genallowed=$user->rights->commande->creer;
- $delallowed=$user->rights->commande->supprimer;
- $somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
-
+ $urlsource = $_SERVER ["PHP_SELF"] . "?id=" . $object->id;
+ $genallowed = $user->rights->commande->creer;
+ $delallowed = $user->rights->commande->supprimer;
+ $somethingshown = $formfile->show_documents('commande', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
+
/*
* Linked object block
*/
- $somethingshown=$object->showLinkedObjectBlock();
-
+ $somethingshown = $object->showLinkedObjectBlock();
+
print ' ';
-
+ // print ' ';
+
// List of actions on element
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
- $formactions=new FormActions($db);
- $somethingshown=$formactions->showactions($object,'order',$socid);
-
- //print '
';
+ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
+ $formactions = new FormActions($db);
+ $somethingshown = $formactions->showactions($object, 'order', $socid);
+
+ // print '
';
print '
';
}
-
-
+
/*
* Action presend
*
*/
- if ($action == 'presend')
- {
+ if ($action == 'presend') {
$ref = dol_sanitizeFileName($object->ref);
- include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
- $file=$fileparams['fullname'];
-
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+ $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/'));
+ $file = $fileparams ['fullname'];
+
// Build document if it not exists
- if (! $file || ! is_readable($file))
- {
+ if (! $file || ! is_readable($file)) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $result=commande_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
+
+ $result = commande_pdf_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($result <= 0) {
+ dol_print_error($db, $result);
+ exit();
}
- $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
- $file=$fileparams['fullname'];
+ $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/'));
+ $file = $fileparams ['fullname'];
}
-
+
print ' ';
print_titre($langs->trans('SendOrderByMail'));
-
+
// Cree l'objet formulaire mail
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->fromtype = 'user';
- $formmail->fromid = $user->id;
+ $formmail->fromid = $user->id;
$formmail->fromname = $user->getFullName($langs);
$formmail->frommail = $user->email;
- $formmail->withfrom=1;
- $liste=array();
- foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
- $formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$liste;
- $formmail->withtocc=$liste;
- $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
- if(empty($object->ref_client))
- {
- $formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__');
+ $formmail->withfrom = 1;
+ $liste = array();
+ foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
+ $liste [$key] = $value;
+ $formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
+ $formmail->withtocc = $liste;
+ $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
+ if (empty($object->ref_client)) {
+ $formmail->withtopic = $langs->trans('SendOrderRef', '__ORDERREF__');
+ } else if (! empty($object->ref_client)) {
+ $formmail->withtopic = $langs->trans('SendOrderRef', '__ORDERREF__(__REFCLIENT__)');
}
- else if(!empty($object->ref_client))
- {
- $formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__(__REFCLIENT__)');
- }
- $formmail->withfile=2;
- $formmail->withbody=1;
- $formmail->withdeliveryreceipt=1;
- $formmail->withcancel=1;
+ $formmail->withfile = 2;
+ $formmail->withbody = 1;
+ $formmail->withdeliveryreceipt = 1;
+ $formmail->withcancel = 1;
// Tableau des substitutions
- $formmail->substit['__ORDERREF__']=$object->ref;
- $formmail->substit['__SIGNATURE__']=$user->signature;
- $formmail->substit['__REFCLIENT__']=$object->ref_client;
- $formmail->substit['__PERSONALIZED__']='';
- $formmail->substit['__CONTACTCIVNAME__']='';
-
- $custcontact='';
- $contactarr=array();
- $contactarr=$object->liste_contact(-1,'external');
-
- if (is_array($contactarr) && count($contactarr)>0) {
- foreach($contactarr as $contact) {
- if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
- $contactstatic=new Contact($db);
- $contactstatic->fetch($contact['id']);
- $custcontact=$contactstatic->getFullName($langs,1);
+ $formmail->substit ['__ORDERREF__'] = $object->ref;
+ $formmail->substit ['__SIGNATURE__'] = $user->signature;
+ $formmail->substit ['__REFCLIENT__'] = $object->ref_client;
+ $formmail->substit ['__PERSONALIZED__'] = '';
+ $formmail->substit ['__CONTACTCIVNAME__'] = '';
+
+ $custcontact = '';
+ $contactarr = array();
+ $contactarr = $object->liste_contact(- 1, 'external');
+
+ if (is_array($contactarr) && count($contactarr) > 0) {
+ foreach ($contactarr as $contact) {
+ if ($contact ['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) {
+ $contactstatic = new Contact($db);
+ $contactstatic->fetch($contact ['id']);
+ $custcontact = $contactstatic->getFullName($langs, 1);
}
}
-
- if (!empty($custcontact)) {
- $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
+
+ if (! empty($custcontact)) {
+ $formmail->substit ['__CONTACTCIVNAME__'] = $custcontact;
}
}
-
+
// Tableau des parametres complementaires
- $formmail->param['action']='send';
- $formmail->param['models']='order_send';
- $formmail->param['orderid']=$object->id;
- $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
-
+ $formmail->param ['action'] = 'send';
+ $formmail->param ['models'] = 'order_send';
+ $formmail->param ['orderid'] = $object->id;
+ $formmail->param ['returnurl'] = $_SERVER ["PHP_SELF"] . '?id=' . $object->id;
+
// Init list of files
- if (GETPOST("mode")=='init')
- {
+ if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
- $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
+ $formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
-
+
// Show form
print $formmail->get_form();
-
+
print ' ';
}
}
}
-
llxFooter();
$db->close();
?>
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 0b18cb6f7cf..d845a364c1d 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -26,11 +26,10 @@
*/
/**
- * \file htdocs/compta/facture.php
- * \ingroup facture
- * \brief Page to create/see an invoice
+ * \file htdocs/compta/facture.php
+ * \ingroup facture
+ * \brief Page to create/see an invoice
*/
-
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
@@ -42,1778 +41,1502 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
-if (! empty($conf->projet->enabled)) {
+if (! empty($conf->commande->enabled))
+ require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
+if (! empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
}
-require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
$langs->load('bills');
$langs->load('companies');
$langs->load('products');
$langs->load('banks');
$langs->load('main');
-if (! empty($conf->margin->enabled)) $langs->load('margins');
+if (! empty($conf->margin->enabled))
+ $langs->load('margins');
-$sall=trim(GETPOST('sall'));
-$projectid=(GETPOST('projectid')?GETPOST('projectid','int'):0);
+$sall = trim(GETPOST('sall'));
+$projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
-$id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
-$ref=GETPOST('ref','alpha');
-$socid=GETPOST('socid','int');
-$action=GETPOST('action','alpha');
-$confirm=GETPOST('confirm','alpha');
-$lineid=GETPOST('lineid','int');
-$userid=GETPOST('userid','int');
-$search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
-$search_societe=GETPOST('search_societe','alpha');
-$search_montant_ht=GETPOST('search_montant_ht','alpha');
-$search_montant_ttc=GETPOST('search_montant_ttc','alpha');
-$origin=GETPOST('origin','alpha');
-$originid=(GETPOST('originid','int')?GETPOST('originid','int'):GETPOST('origin_id','int')); // For backward compatibility
-
-//PDF
-$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
-$hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
-$hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
+$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
+$ref = GETPOST('ref', 'alpha');
+$socid = GETPOST('socid', 'int');
+$action = GETPOST('action', 'alpha');
+$confirm = GETPOST('confirm', 'alpha');
+$lineid = GETPOST('lineid', 'int');
+$userid = GETPOST('userid', 'int');
+$search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
+$search_societe = GETPOST('search_societe', 'alpha');
+$search_montant_ht = GETPOST('search_montant_ht', 'alpha');
+$search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
+$origin = GETPOST('origin', 'alpha');
+$originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
+
+// PDF
+$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
+$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
+$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
// Security check
-$fieldid = (! empty($ref)?'facnumber':'rowid');
-if ($user->societe_id) $socid=$user->societe_id;
-$result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
+$fieldid = (! empty($ref) ? 'facnumber' : 'rowid');
+if ($user->societe_id)
+ $socid = $user->societe_id;
+$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid);
// Nombre de ligne pour choix de produit/service predefinis
-$NBLINES=4;
+$NBLINES = 4;
-$usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:0);
+$usehm = (! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
-$object=new Facture($db);
+$object = new Facture($db);
$extrafields = new ExtraFields($db);
// Load object
-if ($id > 0 || ! empty($ref))
-{
- $ret=$object->fetch($id, $ref);
+if ($id > 0 || ! empty($ref)) {
+ $ret = $object->fetch($id, $ref);
}
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('invoicecard'));
-$permissionnote=$user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
-
+$permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
/*
* Actions
*/
-$parameters=array('socid'=>$socid);
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
-
-include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
-
+$parameters = array('socid' => $socid);
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once
+
// Action clone object
-if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->creer)
-{
- if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
- {
- $mesgs[]=''.$langs->trans("NoCloneOptionsSpecified").'
';
- }
- else
- {
- if ($object->fetch($id) > 0)
- {
- $result=$object->createFromClone($socid);
- if ($result > 0)
- {
- header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result);
- exit;
- }
- else
- {
- $mesgs[]=$object->error;
- $action='';
+if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->creer) {
+ if (1 == 0 && empty($_REQUEST ["clone_content"]) && empty($_REQUEST ["clone_receivers"])) {
+ $mesgs [] = '' . $langs->trans("NoCloneOptionsSpecified") . '
';
+ } else {
+ if ($object->fetch($id) > 0) {
+ $result = $object->createFromClone($socid);
+ if ($result > 0) {
+ header("Location: " . $_SERVER ['PHP_SELF'] . '?facid=' . $result);
+ exit();
+ } else {
+ $mesgs [] = $object->error;
+ $action = '';
}
}
}
-}
+}
// Change status of invoice
-else if ($action == 'reopen' && $user->rights->facture->creer)
-{
+else if ($action == 'reopen' && $user->rights->facture->creer) {
$result = $object->fetch($id);
- if ($object->statut == 2
- || ($object->statut == 3 && $object->close_code != 'replaced'))
- {
+ if ($object->statut == 2 || ($object->statut == 3 && $object->close_code != 'replaced')) {
$result = $object->set_unpaid($user);
- if ($result > 0)
- {
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
- exit;
- }
- else
- {
- $mesgs[]=''.$object->error.'
';
+ if ($result > 0) {
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id);
+ exit();
+ } else {
+ $mesgs [] = '' . $object->error . '
';
}
}
-}
+}
// Delete invoice
-else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->supprimer)
-{
+else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->supprimer) {
$result = $object->fetch($id);
$object->fetch_thirdparty();
-
- $idwarehouse=GETPOST('idwarehouse');
-
- $qualified_for_stock_change=0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(2);
+
+ $idwarehouse = GETPOST('idwarehouse');
+
+ $qualified_for_stock_change = 0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
+ $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ } else {
+ $qualified_for_stock_change = $object->hasProductsOrServices(1);
}
- else
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(1);
+
+ $result = $object->delete(0, 0, $idwarehouse);
+ if ($result > 0) {
+ header('Location: ' . DOL_URL_ROOT . '/compta/facture/list.php');
+ exit();
+ } else {
+ $mesgs [] = '' . $object->error . '
';
}
-
- $result = $object->delete(0,0,$idwarehouse);
- if ($result > 0)
- {
- header('Location: '.DOL_URL_ROOT.'/compta/facture/list.php');
- exit;
- }
- else
- {
- $mesgs[]=''.$object->error.'
';
- }
-}
+}
// Delete line
-else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer)
-{
+else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) {
$object->fetch($id);
$object->fetch_thirdparty();
-
- $result = $object->deleteline($_GET['lineid'], $user);
- if ($result > 0)
- {
+
+ $result = $object->deleteline($_GET ['lineid'], $user);
+ if ($result > 0) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $ret=$object->fetch($id); // Reload to get new records
- $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $ret = $object->fetch($id); // Reload to get new records
+ $result = facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
- if ($result >= 0)
- {
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
- exit;
+ if ($result >= 0) {
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id);
+ exit();
}
+ } else {
+ $mesgs [] = '' . $object->error . '
';
+ $action = '';
}
- else
- {
- $mesgs[]=''.$object->error.'
';
- $action='';
- }
-}
+}
// Delete link of credit note to invoice
-else if ($action == 'unlinkdiscount' && $user->rights->facture->creer)
-{
- $discount=new DiscountAbsolute($db);
- $result=$discount->fetch($_GET["discountid"]);
+else if ($action == 'unlinkdiscount' && $user->rights->facture->creer) {
+ $discount = new DiscountAbsolute($db);
+ $result = $discount->fetch($_GET ["discountid"]);
$discount->unlink_invoice();
-}
+}
// Validation
-else if ($action == 'valid' && $user->rights->facture->creer)
-{
+else if ($action == 'valid' && $user->rights->facture->creer) {
$object->fetch($id);
-
+
// On verifie signe facture
- if ($object->type == 2)
- {
+ if ($object->type == 2) {
// Si avoir, le signe doit etre negatif
- if ($object->total_ht >= 0)
- {
- $mesgs[]=''.$langs->trans("ErrorInvoiceAvoirMustBeNegative").'
';
- $action='';
+ if ($object->total_ht >= 0) {
+ $mesgs [] = '' . $langs->trans("ErrorInvoiceAvoirMustBeNegative") . '
';
+ $action = '';
}
- }
- else
- {
+ } else {
// Si non avoir, le signe doit etre positif
- if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ht < 0)
- {
- $mesgs[]=''.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").'
';
- $action='';
+ if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ht < 0) {
+ $mesgs [] = '' . $langs->trans("ErrorInvoiceOfThisTypeMustBePositive") . '
';
+ $action = '';
}
}
-}
+}
-else if ($action == 'set_thirdparty' && $user->rights->facture->creer)
-{
+else if ($action == 'set_thirdparty' && $user->rights->facture->creer) {
$object->fetch($id);
- $object->setValueFrom('fk_soc',$socid);
+ $object->setValueFrom('fk_soc', $socid);
+
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id);
+ exit();
+}
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
- exit;
-}
+else if ($action == 'classin' && $user->rights->facture->creer) {
+ $object->fetch($id);
+ $object->setProject($_POST ['projectid']);
+}
-else if ($action == 'classin' && $user->rights->facture->creer)
-{
+else if ($action == 'setmode' && $user->rights->facture->creer) {
$object->fetch($id);
- $object->setProject($_POST['projectid']);
-}
-
-else if ($action == 'setmode' && $user->rights->facture->creer)
-{
+ $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+} else if ($action == 'setinvoicedate' && $user->rights->facture->creer) {
$object->fetch($id);
- $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
- if ($result < 0) dol_print_error($db,$object->error);
-}
-else if ($action == 'setinvoicedate' && $user->rights->facture->creer)
-{
- $object->fetch($id);
- $old_date_lim_reglement=$object->date_lim_reglement;
- $object->date=dol_mktime(12,0,0,$_POST['invoicedatemonth'],$_POST['invoicedateday'],$_POST['invoicedateyear']);
- $new_date_lim_reglement=$object->calculate_date_lim_reglement();
- if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement=$new_date_lim_reglement;
- if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date;
- $result=$object->update($user);
- if ($result < 0) dol_print_error($db,$object->error);
-}
-else if ($action == 'setconditions' && $user->rights->facture->creer)
-{
- $object->fetch($id);
- $object->cond_reglement_code=0; // To clean property
- $object->cond_reglement_id=0; // To clean property
- $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
- if ($result < 0) dol_print_error($db,$object->error);
-
- $old_date_lim_reglement=$object->date_lim_reglement;
- $new_date_lim_reglement=$object->calculate_date_lim_reglement();
- if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement=$new_date_lim_reglement;
- if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date;
- $result=$object->update($user);
- if ($result < 0) dol_print_error($db,$object->error);
-}
-else if ($action == 'setpaymentterm' && $user->rights->facture->creer)
-{
- $object->fetch($id);
- $object->date_lim_reglement=dol_mktime(12,0,0,$_POST['paymenttermmonth'],$_POST['paymenttermday'],$_POST['paymenttermyear']);
+ $old_date_lim_reglement = $object->date_lim_reglement;
+ $object->date = dol_mktime(12, 0, 0, $_POST ['invoicedatemonth'], $_POST ['invoicedateday'], $_POST ['invoicedateyear']);
+ $new_date_lim_reglement = $object->calculate_date_lim_reglement();
+ if ($new_date_lim_reglement > $old_date_lim_reglement)
+ $object->date_lim_reglement = $new_date_lim_reglement;
if ($object->date_lim_reglement < $object->date)
- {
- $object->date_lim_reglement=$object->calculate_date_lim_reglement();
- setEventMessage($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"),'warnings');
- }
- $result=$object->update($user);
- if ($result < 0) dol_print_error($db,$object->error);
-}
-else if ($action == 'setrevenuestamp' && $user->rights->facture->creer)
-{
+ $object->date_lim_reglement = $object->date;
+ $result = $object->update($user);
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+} else if ($action == 'setconditions' && $user->rights->facture->creer) {
$object->fetch($id);
- $object->revenuestamp=GETPOST('revenuestamp');
- $result=$object->update($user);
+ $object->cond_reglement_code = 0; // To clean property
+ $object->cond_reglement_id = 0; // To clean property
+ $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+
+ $old_date_lim_reglement = $object->date_lim_reglement;
+ $new_date_lim_reglement = $object->calculate_date_lim_reglement();
+ if ($new_date_lim_reglement > $old_date_lim_reglement)
+ $object->date_lim_reglement = $new_date_lim_reglement;
+ if ($object->date_lim_reglement < $object->date)
+ $object->date_lim_reglement = $object->date;
+ $result = $object->update($user);
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+} else if ($action == 'setpaymentterm' && $user->rights->facture->creer) {
+ $object->fetch($id);
+ $object->date_lim_reglement = dol_mktime(12, 0, 0, $_POST ['paymenttermmonth'], $_POST ['paymenttermday'], $_POST ['paymenttermyear']);
+ if ($object->date_lim_reglement < $object->date) {
+ $object->date_lim_reglement = $object->calculate_date_lim_reglement();
+ setEventMessage($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"), 'warnings');
+ }
+ $result = $object->update($user);
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+} else if ($action == 'setrevenuestamp' && $user->rights->facture->creer) {
+ $object->fetch($id);
+ $object->revenuestamp = GETPOST('revenuestamp');
+ $result = $object->update($user);
$object->update_price(1);
- if ($result < 0) dol_print_error($db,$object->error);
-}
-else if ($action == 'setremisepercent' && $user->rights->facture->creer)
-{
+ if ($result < 0)
+ dol_print_error($db, $object->error);
+} else if ($action == 'setremisepercent' && $user->rights->facture->creer) {
$object->fetch($id);
- $result = $object->set_remise($user, $_POST['remise_percent']);
-}
-else if ($action == "setabsolutediscount" && $user->rights->facture->creer)
-{
+ $result = $object->set_remise($user, $_POST ['remise_percent']);
+} else if ($action == "setabsolutediscount" && $user->rights->facture->creer) {
// POST[remise_id] ou POST[remise_id_for_payment]
- if (! empty($_POST["remise_id"]))
- {
- $ret=$object->fetch($id);
- if ($ret > 0)
- {
- $result=$object->insert_discount($_POST["remise_id"]);
- if ($result < 0)
- {
- $mesgs[]=''.$object->error.'
';
+ if (! empty($_POST ["remise_id"])) {
+ $ret = $object->fetch($id);
+ if ($ret > 0) {
+ $result = $object->insert_discount($_POST ["remise_id"]);
+ if ($result < 0) {
+ $mesgs [] = '' . $object->error . '
';
}
- }
- else
- {
- dol_print_error($db,$object->error);
+ } else {
+ dol_print_error($db, $object->error);
}
}
- if (! empty($_POST["remise_id_for_payment"]))
- {
- require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
+ if (! empty($_POST ["remise_id_for_payment"])) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
$discount = new DiscountAbsolute($db);
- $discount->fetch($_POST["remise_id_for_payment"]);
-
- $result=$discount->link_to_invoice(0,$id);
- if ($result < 0)
- {
- $mesgs[]=''.$discount->error.'
';
+ $discount->fetch($_POST ["remise_id_for_payment"]);
+
+ $result = $discount->link_to_invoice(0, $id);
+ if ($result < 0) {
+ $mesgs [] = '' . $discount->error . '
';
}
}
-}
+}
-else if ($action == 'set_ref_client' && $user->rights->facture->creer)
-{
+else if ($action == 'set_ref_client' && $user->rights->facture->creer) {
$object->fetch($id);
- $object->set_ref_client($_POST['ref_client']);
-}
+ $object->set_ref_client($_POST ['ref_client']);
+}
// Classify to validated
-else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->valider)
-{
- $idwarehouse=GETPOST('idwarehouse');
-
+else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->valider) {
+ $idwarehouse = GETPOST('idwarehouse');
+
$object->fetch($id);
$object->fetch_thirdparty();
-
+
// Check parameters
-
- // Check for mandatory prof id
- for ($i = 1; $i < 5; $i++)
- {
-
- $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_INVOICE_MANDATORY';
- $idprof='idprof'.$i;
- if (! $object->thirdparty->$idprof && ! empty($conf->global->$idprof_mandatory))
- {
- if (! $error) $langs->load("errors");
- $error++;
-
- setEventMessage($langs->trans('ErrorProdIdIsMandatory',$langs->transcountry('ProfId'.$i, $object->thirdparty->country_code)),'errors');
+
+ // Check for mandatory prof id
+ for($i = 1; $i < 5; $i ++) {
+
+ $idprof_mandatory = 'SOCIETE_IDPROF' . ($i) . '_INVOICE_MANDATORY';
+ $idprof = 'idprof' . $i;
+ if (! $object->thirdparty->$idprof && ! empty($conf->global->$idprof_mandatory)) {
+ if (! $error)
+ $langs->load("errors");
+ $error ++;
+
+ setEventMessage($langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId' . $i, $object->thirdparty->country_code)), 'errors');
}
}
-
- $qualified_for_stock_change=0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(2);
+
+ $qualified_for_stock_change = 0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
+ $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ } else {
+ $qualified_for_stock_change = $object->hasProductsOrServices(1);
}
- else
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(1);
- }
-
- //Check for warehouse
- if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")),'errors');
- $action='';
+
+ // Check for warehouse
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
+ if (! $idwarehouse || $idwarehouse == - 1) {
+ $error ++;
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), 'errors');
+ $action = '';
}
}
-
- if (! $error)
- {
- $result = $object->validate($user,'',$idwarehouse);
- if ($result >= 0)
- {
+
+ if (! $error) {
+ $result = $object->validate($user, '', $idwarehouse);
+ if ($result >= 0) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $ret=$object->fetch($id); // Reload to get new records
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $ret = $object->fetch($id); // Reload to get new records
facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
- }
- else
- {
- setEventMessage($object->error,'errors');
+ } else {
+ setEventMessage($object->error, 'errors');
}
}
-}
+}
// Go back to draft status (unvalidate)
-else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate))
-{
- $idwarehouse=GETPOST('idwarehouse');
-
+else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate)) {
+ $idwarehouse = GETPOST('idwarehouse');
+
$object->fetch($id);
$object->fetch_thirdparty();
-
- $qualified_for_stock_change=0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(2);
+
+ $qualified_for_stock_change = 0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
+ $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ } else {
+ $qualified_for_stock_change = $object->hasProductsOrServices(1);
}
- else
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(1);
- }
-
+
// Check parameters
- if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")),'errors');
- $action='';
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
+ if (! $idwarehouse || $idwarehouse == - 1) {
+ $error ++;
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), 'errors');
+ $action = '';
}
}
-
- if (! $error)
- {
+
+ if (! $error) {
// On verifie si la facture a des paiements
$sql = 'SELECT pf.amount';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
- $sql.= ' WHERE pf.fk_facture = '.$object->id;
-
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf';
+ $sql .= ' WHERE pf.fk_facture = ' . $object->id;
+
$result = $db->query($sql);
- if ($result)
- {
+ if ($result) {
$i = 0;
$num = $db->num_rows($result);
-
- while ($i < $num)
- {
+
+ while ($i < $num) {
$objp = $db->fetch_object($result);
$totalpaye += $objp->amount;
- $i++;
+ $i ++;
}
+ } else {
+ dol_print_error($db, '');
}
- else
- {
- dol_print_error($db,'');
- }
-
+
$resteapayer = $object->total_ttc - $totalpaye;
-
+
// On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
$ventilExportCompta = $object->getVentilExportCompta();
-
+
// On verifie si aucun paiement n'a ete effectue
- if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
- {
+ if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) {
$object->set_draft($user, $idwarehouse);
-
+
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $ret=$object->fetch($id); // Reload to get new records
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $ret = $object->fetch($id); // Reload to get new records
facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
}
}
-}
+}
// Classify "paid"
-else if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->facture->paiement)
-{
+else if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->facture->paiement) {
$object->fetch($id);
$result = $object->set_paid($user);
-}
-// Classif "paid partialy"
-else if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $user->rights->facture->paiement)
-{
+} // Classif "paid partialy"
+else if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $user->rights->facture->paiement) {
$object->fetch($id);
- $close_code=$_POST["close_code"];
- $close_note=$_POST["close_note"];
- if ($close_code)
- {
- $result = $object->set_paid($user,$close_code,$close_note);
+ $close_code = $_POST ["close_code"];
+ $close_note = $_POST ["close_note"];
+ if ($close_code) {
+ $result = $object->set_paid($user, $close_code, $close_note);
+ } else {
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), 'errors');
}
- else
- {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Reason")),'errors');
- }
-}
-// Classify "abandoned"
-else if ($action == 'confirm_canceled' && $confirm == 'yes')
-{
+} // Classify "abandoned"
+else if ($action == 'confirm_canceled' && $confirm == 'yes') {
$object->fetch($id);
- $close_code=$_POST["close_code"];
- $close_note=$_POST["close_note"];
- if ($close_code)
- {
- $result = $object->set_canceled($user,$close_code,$close_note);
+ $close_code = $_POST ["close_code"];
+ $close_note = $_POST ["close_note"];
+ if ($close_code) {
+ $result = $object->set_canceled($user, $close_code, $close_note);
+ } else {
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), 'errors');
}
- else
- {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Reason")),'errors');
- }
-}
+}
// Convertir en reduc
-else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer)
-{
+else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer) {
$db->begin();
-
+
$object->fetch($id);
$object->fetch_thirdparty();
$object->fetch_lines();
-
- if (! $object->paye) // protection against multiple submit
+
+ if (! $object->paye) // protection against multiple submit
{
// Boucle sur chaque taux de tva
- $i=0;
- foreach($object->lines as $line)
- {
- $amount_ht[$line->tva_tx]+=$line->total_ht;
- $amount_tva[$line->tva_tx]+=$line->total_tva;
- $amount_ttc[$line->tva_tx]+=$line->total_ttc;
- $i++;
+ $i = 0;
+ foreach ($object->lines as $line) {
+ $amount_ht [$line->tva_tx] += $line->total_ht;
+ $amount_tva [$line->tva_tx] += $line->total_tva;
+ $amount_ttc [$line->tva_tx] += $line->total_ttc;
+ $i ++;
}
-
+
// Insert one discount by VAT rate category
$discount = new DiscountAbsolute($db);
- if ($object->type == 2) $discount->description='(CREDIT_NOTE)';
- elseif ($object->type == 3) $discount->description='(DEPOSIT)';
+ if ($object->type == 2)
+ $discount->description = '(CREDIT_NOTE)';
+ elseif ($object->type == 3)
+ $discount->description = '(DEPOSIT)';
else {
- $this->error="CantConvertToReducAnInvoiceOfThisType";
- return -1;
+ $this->error = "CantConvertToReducAnInvoiceOfThisType";
+ return - 1;
}
- $discount->tva_tx=abs($object->total_ttc);
- $discount->fk_soc=$object->socid;
- $discount->fk_facture_source=$object->id;
-
- $error=0;
- foreach($amount_ht as $tva_tx => $xxx)
- {
- $discount->amount_ht=abs($amount_ht[$tva_tx]);
- $discount->amount_tva=abs($amount_tva[$tva_tx]);
- $discount->amount_ttc=abs($amount_ttc[$tva_tx]);
- $discount->tva_tx=abs($tva_tx);
-
- $result=$discount->create($user);
- if ($result < 0)
- {
- $error++;
+ $discount->tva_tx = abs($object->total_ttc);
+ $discount->fk_soc = $object->socid;
+ $discount->fk_facture_source = $object->id;
+
+ $error = 0;
+ foreach ($amount_ht as $tva_tx => $xxx) {
+ $discount->amount_ht = abs($amount_ht [$tva_tx]);
+ $discount->amount_tva = abs($amount_tva [$tva_tx]);
+ $discount->amount_ttc = abs($amount_ttc [$tva_tx]);
+ $discount->tva_tx = abs($tva_tx);
+
+ $result = $discount->create($user);
+ if ($result < 0) {
+ $error ++;
break;
}
}
-
- if (! $error)
- {
+
+ if (! $error) {
// Classe facture
- $result=$object->set_paid($user);
- if ($result > 0)
- {
- //$mesgs[]='OK'.$discount->id;
+ $result = $object->set_paid($user);
+ if ($result > 0) {
+ // $mesgs[]='OK'.$discount->id;
$db->commit();
- }
- else
- {
- $mesgs[]=''.$object->error.'
';
+ } else {
+ $mesgs [] = '' . $object->error . '
';
$db->rollback();
}
- }
- else
- {
- $mesgs[]=''.$discount->error.'
';
+ } else {
+ $mesgs [] = '' . $discount->error . '
';
$db->rollback();
}
}
-}
+}
/*
* Insert new invoice in database
*/
-else if ($action == 'add' && $user->rights->facture->creer)
-{
- if ($socid>0)
- $object->socid=GETPOST('socid','int');
-
+else if ($action == 'add' && $user->rights->facture->creer) {
+ if ($socid > 0)
+ $object->socid = GETPOST('socid', 'int');
+
$db->begin();
-
- $error=0;
-
+
+ $error = 0;
+
// Fill array 'array_options' with data from add form
- $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
- if($ret < 0)
- $error++;
-
- // Replacement invoice
- if ($_POST['type'] == 1)
- {
- $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
+ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+ $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
+ if ($ret < 0)
+ $error ++;
+
+ // Replacement invoice
+ if ($_POST ['type'] == 1) {
+ $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']);
+ if (empty($datefacture)) {
+ $error ++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
}
-
- if (! ($_POST['fac_replacement'] > 0))
- {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ReplaceInvoice")),'errors');
+
+ if (! ($_POST ['fac_replacement'] > 0)) {
+ $error ++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReplaceInvoice")), 'errors');
}
-
- if (! $error)
- {
+
+ if (! $error) {
// This is a replacement invoice
- $result=$object->fetch($_POST['fac_replacement']);
+ $result = $object->fetch($_POST ['fac_replacement']);
$object->fetch_thirdparty();
-
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note = trim($_POST['note']);
- $object->ref_client = $_POST['ref_client'];
- $object->ref_int = $_POST['ref_int'];
- $object->modelpdf = $_POST['model'];
- $object->fk_project = $_POST['projectid'];
- $object->cond_reglement_id = $_POST['cond_reglement_id'];
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
- $object->remise_absolue = $_POST['remise_absolue'];
- $object->remise_percent = $_POST['remise_percent'];
-
+
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST ['note_public']);
+ $object->note = trim($_POST ['note']);
+ $object->ref_client = $_POST ['ref_client'];
+ $object->ref_int = $_POST ['ref_int'];
+ $object->modelpdf = $_POST ['model'];
+ $object->fk_project = $_POST ['projectid'];
+ $object->cond_reglement_id = $_POST ['cond_reglement_id'];
+ $object->mode_reglement_id = $_POST ['mode_reglement_id'];
+ $object->remise_absolue = $_POST ['remise_absolue'];
+ $object->remise_percent = $_POST ['remise_percent'];
+
// Proprietes particulieres a facture de remplacement
- $object->fk_facture_source = $_POST['fac_replacement'];
- $object->type = 1;
-
- $id=$object->createFromCurrent($user);
- if ($id <= 0) $mesgs[]=$object->error;
+ $object->fk_facture_source = $_POST ['fac_replacement'];
+ $object->type = 1;
+
+ $id = $object->createFromCurrent($user);
+ if ($id <= 0)
+ $mesgs [] = $object->error;
}
}
-
+
// Credit note invoice
- if ($_POST['type'] == 2)
- {
- if (! $_POST['fac_avoir'] > 0)
- {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CorrectInvoice")),'errors');
+ if ($_POST ['type'] == 2) {
+ if (! $_POST ['fac_avoir'] > 0) {
+ $error ++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CorrectInvoice")), 'errors');
}
-
- $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")),'errors');
+
+ $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']);
+ if (empty($datefacture)) {
+ $error ++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->trans("Date")), 'errors');
}
-
- if (! $error)
- {
+
+ if (! $error) {
// Si facture avoir
- $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
-
- //$result=$object->fetch($_POST['fac_avoir']);
-
- $object->socid = GETPOST('socid','int');
- $object->number = $_POST['facnumber'];
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note = trim($_POST['note']);
- $object->ref_client = $_POST['ref_client'];
- $object->ref_int = $_POST['ref_int'];
- $object->modelpdf = $_POST['model'];
- $object->fk_project = $_POST['projectid'];
- $object->cond_reglement_id = 0;
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
- $object->remise_absolue = $_POST['remise_absolue'];
- $object->remise_percent = $_POST['remise_percent'];
-
+ $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']);
+
+ // $result=$object->fetch($_POST['fac_avoir']);
+
+ $object->socid = GETPOST('socid', 'int');
+ $object->number = $_POST ['facnumber'];
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST ['note_public']);
+ $object->note = trim($_POST ['note']);
+ $object->ref_client = $_POST ['ref_client'];
+ $object->ref_int = $_POST ['ref_int'];
+ $object->modelpdf = $_POST ['model'];
+ $object->fk_project = $_POST ['projectid'];
+ $object->cond_reglement_id = 0;
+ $object->mode_reglement_id = $_POST ['mode_reglement_id'];
+ $object->remise_absolue = $_POST ['remise_absolue'];
+ $object->remise_percent = $_POST ['remise_percent'];
+
// Proprietes particulieres a facture avoir
- $object->fk_facture_source = $_POST['fac_avoir'];
- $object->type = 2;
-
+ $object->fk_facture_source = $_POST ['fac_avoir'];
+ $object->type = 2;
+
$id = $object->create($user);
-
+
// Add predefined lines
- for ($i = 1; $i <= $NBLINES; $i++)
- {
- if ($_POST['idprod'.$i])
- {
- $product=new Product($db);
- $product->fetch($_POST['idprod'.$i]);
- $startday=dol_mktime(12, 0, 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']);
- $endday=dol_mktime(12, 0, 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']);
- $result=$object->addline($product->description,$product->price, $_POST['qty'.$i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod'.$i], $_POST['remise_percent'.$i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
+ for($i = 1; $i <= $NBLINES; $i ++) {
+ if ($_POST ['idprod' . $i]) {
+ $product = new Product($db);
+ $product->fetch($_POST ['idprod' . $i]);
+ $startday = dol_mktime(12, 0, 0, $_POST ['date_start' . $i . 'month'], $_POST ['date_start' . $i . 'day'], $_POST ['date_start' . $i . 'year']);
+ $endday = dol_mktime(12, 0, 0, $_POST ['date_end' . $i . 'month'], $_POST ['date_end' . $i . 'day'], $_POST ['date_end' . $i . 'year']);
+ $result = $object->addline($product->description, $product->price, $_POST ['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST ['idprod' . $i], $_POST ['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
}
}
}
}
-
+
// Standard invoice or Deposit invoice created from a Predefined invoice
- if (($_POST['type'] == 0 || $_POST['type'] == 3) && $_POST['fac_rec'] > 0)
- {
- $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
+ if (($_POST ['type'] == 0 || $_POST ['type'] == 3) && $_POST ['fac_rec'] > 0) {
+ $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']);
+ if (empty($datefacture)) {
+ $error ++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
}
-
- if (! $error)
- {
- $object->socid = GETPOST('socid','int');
- $object->type = $_POST['type'];
- $object->number = $_POST['facnumber'];
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note_private = trim($_POST['note_private']);
- $object->ref_client = $_POST['ref_client'];
- $object->ref_int = $_POST['ref_int'];
- $object->modelpdf = $_POST['model'];
-
+
+ if (! $error) {
+ $object->socid = GETPOST('socid', 'int');
+ $object->type = $_POST ['type'];
+ $object->number = $_POST ['facnumber'];
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST ['note_public']);
+ $object->note_private = trim($_POST ['note_private']);
+ $object->ref_client = $_POST ['ref_client'];
+ $object->ref_int = $_POST ['ref_int'];
+ $object->modelpdf = $_POST ['model'];
+
// Source facture
- $object->fac_rec = $_POST['fac_rec'];
-
+ $object->fac_rec = $_POST ['fac_rec'];
+
$id = $object->create($user);
}
}
-
-
-
+
// Standard or deposit or proforma invoice
- if (($_POST['type'] == 0 || $_POST['type'] == 3 || $_POST['type'] == 4) && $_POST['fac_rec'] <= 0)
- {
- if (GETPOST('socid','int')<1)
- {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Customer")),'errors');
+ if (($_POST ['type'] == 0 || $_POST ['type'] == 3 || $_POST ['type'] == 4) && $_POST ['fac_rec'] <= 0) {
+ if (GETPOST('socid', 'int') < 1) {
+ $error ++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), 'errors');
}
-
- $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error++;
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
+
+ $datefacture = dol_mktime(12, 0, 0, $_POST ['remonth'], $_POST ['reday'], $_POST ['reyear']);
+ if (empty($datefacture)) {
+ $error ++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
}
-
- if (! $error)
- {
+
+ if (! $error) {
// Si facture standard
- $object->socid = GETPOST('socid','int');
- $object->type = GETPOST('type');
- $object->number = $_POST['facnumber'];
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note_private = trim($_POST['note_private']);
- $object->ref_client = $_POST['ref_client'];
- $object->ref_int = $_POST['ref_int'];
- $object->modelpdf = $_POST['model'];
- $object->fk_project = $_POST['projectid'];
- $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']);
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
- $object->amount = $_POST['amount'];
- $object->remise_absolue = $_POST['remise_absolue'];
- $object->remise_percent = $_POST['remise_percent'];
+ $object->socid = GETPOST('socid', 'int');
+ $object->type = GETPOST('type');
+ $object->number = $_POST ['facnumber'];
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST ['note_public']);
+ $object->note_private = trim($_POST ['note_private']);
+ $object->ref_client = $_POST ['ref_client'];
+ $object->ref_int = $_POST ['ref_int'];
+ $object->modelpdf = $_POST ['model'];
+ $object->fk_project = $_POST ['projectid'];
+ $object->cond_reglement_id = ($_POST ['type'] == 3 ? 1 : $_POST ['cond_reglement_id']);
+ $object->mode_reglement_id = $_POST ['mode_reglement_id'];
+ $object->amount = $_POST ['amount'];
+ $object->remise_absolue = $_POST ['remise_absolue'];
+ $object->remise_percent = $_POST ['remise_percent'];
$object->fetch_thirdparty();
-
+
// If creation from another object of another module (Example: origin=propal, originid=1)
- if ($_POST['origin'] && $_POST['originid'])
- {
+ if ($_POST ['origin'] && $_POST ['originid']) {
// Parse element/subelement (ex: project_task)
- $element = $subelement = $_POST['origin'];
- if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs))
- {
- $element = $regs[1];
- $subelement = $regs[2];
+ $element = $subelement = $_POST ['origin'];
+ if (preg_match('/^([^_]+)_([^_]+)/i', $_POST ['origin'], $regs)) {
+ $element = $regs [1];
+ $subelement = $regs [2];
}
-
+
// For compatibility
- if ($element == 'order') {
+ if ($element == 'order') {
$element = $subelement = 'commande';
}
- if ($element == 'propal') {
- $element = 'comm/propal'; $subelement = 'propal';
+ if ($element == 'propal') {
+ $element = 'comm/propal';
+ $subelement = 'propal';
}
if ($element == 'contract') {
$element = $subelement = 'contrat';
}
- if ($element == 'inter') {
+ if ($element == 'inter') {
$element = $subelement = 'ficheinter';
}
if ($element == 'shipping') {
$element = $subelement = 'expedition';
}
-
- $object->origin = $_POST['origin'];
- $object->origin_id = $_POST['originid'];
-
+
+ $object->origin = $_POST ['origin'];
+ $object->origin_id = $_POST ['originid'];
+
// Possibility to add external linked objects with hooks
- $object->linked_objects[$object->origin] = $object->origin_id;
- if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
- {
- $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
+ $object->linked_objects [$object->origin] = $object->origin_id;
+ if (is_array($_POST ['other_linked_objects']) && ! empty($_POST ['other_linked_objects'])) {
+ $object->linked_objects = array_merge($object->linked_objects, $_POST ['other_linked_objects']);
}
-
+
$id = $object->create($user);
-
- if ($id > 0)
- {
+
+ if ($id > 0) {
// If deposit invoice
- if ($_POST['type'] == 3)
- {
- $typeamount=GETPOST('typedeposit','alpha');
- $valuedeposit=GETPOST('valuedeposit','int');
-
- if ($typeamount=='amount')
- {
- $amountdeposit=$valuedeposit;
- }
- else
- {
- $amountdeposit=0;
-
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
-
+ if ($_POST ['type'] == 3) {
+ $typeamount = GETPOST('typedeposit', 'alpha');
+ $valuedeposit = GETPOST('valuedeposit', 'int');
+
+ if ($typeamount == 'amount') {
+ $amountdeposit = $valuedeposit;
+ } else {
+ $amountdeposit = 0;
+
+ dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
+
$classname = ucfirst($subelement);
$srcobject = new $classname($db);
-
- dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add deposit lines");
- $result=$srcobject->fetch($object->origin_id);
- if ($result > 0)
- {
- $totalamount=0;
+
+ dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add deposit lines");
+ $result = $srcobject->fetch($object->origin_id);
+ if ($result > 0) {
+ $totalamount = 0;
$lines = $srcobject->lines;
- $numlines=count($lines);
- for ($i=0; $i<$numlines; $i++)
- {
- $totalamount += $lines[$i]->total_ht;
+ $numlines = count($lines);
+ for($i = 0; $i < $numlines; $i ++) {
+ $totalamount += $lines [$i]->total_ht;
}
-
- if ($totalamount!=0)
- {
- $amountdeposit=($totalamount*$valuedeposit)/100;
+
+ if ($totalamount != 0) {
+ $amountdeposit = ($totalamount * $valuedeposit) / 100;
}
+ } else {
+ $mesgs [] = $srcobject->error;
+ $error ++;
}
- else
- {
- $mesgs[]=$srcobject->error;
- $error++;
- }
-
}
-
+
$result = $object->addline(
- $langs->trans('Deposit'),
- $amountdeposit, //subprice
- 1, //quantity
- $lines[$i]->tva_tx,
- 0, //localtax1_tx
- 0, //localtax2_tx
- 0, //fk_product
- 0, //remise_percent
- 0, //date_start
- 0, //date_end
- 0,
- $lines[$i]->info_bits, //info_bits
- 0, //info_bits
- 'HT',
- 0,
- 0, //product_type
- 1,
- $lines[$i]->special_code,
- $object->origin,
- 0,
- 0,
- 0,
- 0,
- $langs->trans('Deposit')
- );
-
-
- }else {
-
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
-
+ $langs->trans('Deposit'),
+ $amountdeposit, // subprice
+ 1, // quantity
+ $lines [$i]->tva_tx, 0, // localtax1_tx
+ 0, // localtax2_tx
+ 0, // fk_product
+ 0, // remise_percent
+ 0, // date_start
+ 0, // date_end
+ 0, $lines [$i]->info_bits, // info_bits
+ 0, // info_bits
+ 'HT',
+ 0,
+ 0, // product_type
+ 1,
+ $lines [$i]->special_code,
+ $object->origin,
+ 0,
+ 0,
+ 0,
+ 0,
+ $langs->trans('Deposit')
+ );
+ } else {
+
+ dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
+
$classname = ucfirst($subelement);
$srcobject = new $classname($db);
-
- dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
- $result=$srcobject->fetch($object->origin_id);
- if ($result > 0)
- {
+
+ dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
+ $result = $srcobject->fetch($object->origin_id);
+ if ($result > 0) {
$lines = $srcobject->lines;
- if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
-
- $fk_parent_line=0;
- $num=count($lines);
-
- for ($i=0;$i<$num;$i++)
- {
- $label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
- $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
-
- if ($lines[$i]->subprice < 0)
- {
+ if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
+ $lines = $srcobject->fetch_lines();
+
+ $fk_parent_line = 0;
+ $num = count($lines);
+
+ for($i = 0; $i < $num; $i ++) {
+ $label = (! empty($lines [$i]->label) ? $lines [$i]->label : '');
+ $desc = (! empty($lines [$i]->desc) ? $lines [$i]->desc : $lines [$i]->libelle);
+
+ if ($lines [$i]->subprice < 0) {
// Negative line, we create a discount line
$discount = new DiscountAbsolute($db);
- $discount->fk_soc=$object->socid;
- $discount->amount_ht=abs($lines[$i]->total_ht);
- $discount->amount_tva=abs($lines[$i]->total_tva);
- $discount->amount_ttc=abs($lines[$i]->total_ttc);
- $discount->tva_tx=$lines[$i]->tva_tx;
- $discount->fk_user=$user->id;
- $discount->description=$desc;
- $discountid=$discount->create($user);
- if ($discountid > 0)
- {
- $result=$object->insert_discount($discountid); // This include link_to_invoice
- }
- else
- {
- $mesgs[]=$discount->error;
- $error++;
+ $discount->fk_soc = $object->socid;
+ $discount->amount_ht = abs($lines [$i]->total_ht);
+ $discount->amount_tva = abs($lines [$i]->total_tva);
+ $discount->amount_ttc = abs($lines [$i]->total_ttc);
+ $discount->tva_tx = $lines [$i]->tva_tx;
+ $discount->fk_user = $user->id;
+ $discount->description = $desc;
+ $discountid = $discount->create($user);
+ if ($discountid > 0) {
+ $result = $object->insert_discount($discountid); // This include link_to_invoice
+ } else {
+ $mesgs [] = $discount->error;
+ $error ++;
break;
}
- }
- else
- {
+ } else {
// Positive line
- $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
-
+ $product_type = ($lines [$i]->product_type ? $lines [$i]->product_type : 0);
+
// Date start
- $date_start=false;
- if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
- if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
- if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
-
- //Date end
- $date_end=false;
- if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
- if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
- if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
-
- // Reset fk_parent_line for no child products and special product
- if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
+ $date_start = false;
+ if ($lines [$i]->date_debut_prevue)
+ $date_start = $lines [$i]->date_debut_prevue;
+ if ($lines [$i]->date_debut_reel)
+ $date_start = $lines [$i]->date_debut_reel;
+ if ($lines [$i]->date_start)
+ $date_start = $lines [$i]->date_start;
+
+ // Date end
+ $date_end = false;
+ if ($lines [$i]->date_fin_prevue)
+ $date_end = $lines [$i]->date_fin_prevue;
+ if ($lines [$i]->date_fin_reel)
+ $date_end = $lines [$i]->date_fin_reel;
+ if ($lines [$i]->date_end)
+ $date_end = $lines [$i]->date_end;
+
+ // Reset fk_parent_line for no child products and special product
+ if (($lines [$i]->product_type != 9 && empty($lines [$i]->fk_parent_line)) || $lines [$i]->product_type == 9) {
$fk_parent_line = 0;
}
-
- //Extrafields
- if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i],'fetch_optionals'))
- {
- $lines[$i]->fetch_optionals($lines[$i]->rowid);
- $array_option=$lines[$i]->array_options;
+
+ // Extrafields
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines [$i], 'fetch_optionals')) {
+ $lines [$i]->fetch_optionals($lines [$i]->rowid);
+ $array_option = $lines [$i]->array_options;
}
-
- $result = $object->addline(
- $desc,
- $lines[$i]->subprice,
- $lines[$i]->qty,
- $lines[$i]->tva_tx,
- $lines[$i]->localtax1_tx,
- $lines[$i]->localtax2_tx,
- $lines[$i]->fk_product,
- $lines[$i]->remise_percent,
- $date_start,
- $date_end,
- 0,
- $lines[$i]->info_bits,
- $lines[$i]->fk_remise_except,
- 'HT',
- 0,
- $product_type,
- $lines[$i]->rang,
- $lines[$i]->special_code,
- $object->origin,
- $lines[$i]->rowid,
- $fk_parent_line,
- $lines[$i]->fk_fournprice,
- $lines[$i]->pa_ht,
- $label,
- $array_option
- );
-
- if ($result > 0)
- {
- $lineid=$result;
- }
- else
- {
- $lineid=0;
- $error++;
+
+ $result = $object->addline($desc, $lines [$i]->subprice, $lines [$i]->qty, $lines [$i]->tva_tx, $lines [$i]->localtax1_tx, $lines [$i]->localtax2_tx, $lines [$i]->fk_product, $lines [$i]->remise_percent, $date_start, $date_end, 0, $lines [$i]->info_bits, $lines [$i]->fk_remise_except, 'HT', 0, $product_type, $lines [$i]->rang, $lines [$i]->special_code, $object->origin, $lines [$i]->rowid, $fk_parent_line, $lines [$i]->fk_fournprice, $lines [$i]->pa_ht, $label, $array_option);
+
+ if ($result > 0) {
+ $lineid = $result;
+ } else {
+ $lineid = 0;
+ $error ++;
break;
}
-
+
// Defined the new fk_parent_line
- if ($result > 0 && $lines[$i]->product_type == 9) {
+ if ($result > 0 && $lines [$i]->product_type == 9) {
$fk_parent_line = $result;
}
}
}
-
+
// Hooks
- $parameters=array('objFrom'=>$srcobject);
- $reshook=$hookmanager->executeHooks('createFrom',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if ($reshook < 0) $error++;
- }
- else
- {
- $mesgs[]=$srcobject->error;
- $error++;
+ $parameters = array('objFrom' => $srcobject);
+ $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified by hook
+ if ($reshook < 0)
+ $error ++;
+ } else {
+ $mesgs [] = $srcobject->error;
+ $error ++;
}
}
+ } else {
+ $mesgs [] = $object->error;
+ $error ++;
}
- else
- {
- $mesgs[]=$object->error;
- $error++;
- }
- }
- // If some invoice's lines already known
- else
- {
+ } // If some invoice's lines already known
+ else {
$id = $object->create($user);
-
- for ($i = 1; $i <= $NBLINES; $i++)
- {
- if ($_POST['idprod'.$i])
- {
- $product=new Product($db);
- $product->fetch($_POST['idprod'.$i]);
- $startday=dol_mktime(12, 0, 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']);
- $endday=dol_mktime(12, 0, 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']);
- $result=$object->addline($product->description,$product->price, $_POST['qty'.$i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod'.$i], $_POST['remise_percent'.$i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
+
+ for($i = 1; $i <= $NBLINES; $i ++) {
+ if ($_POST ['idprod' . $i]) {
+ $product = new Product($db);
+ $product->fetch($_POST ['idprod' . $i]);
+ $startday = dol_mktime(12, 0, 0, $_POST ['date_start' . $i . 'month'], $_POST ['date_start' . $i . 'day'], $_POST ['date_start' . $i . 'year']);
+ $endday = dol_mktime(12, 0, 0, $_POST ['date_end' . $i . 'month'], $_POST ['date_end' . $i . 'day'], $_POST ['date_end' . $i . 'year']);
+ $result = $object->addline($product->description, $product->price, $_POST ['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST ['idprod' . $i], $_POST ['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
}
}
}
}
}
-
+
// End of object creation, we show it
- if ($id > 0 && ! $error)
- {
+ if ($id > 0 && ! $error) {
$db->commit();
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
- exit;
- }
- else
- {
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id);
+ exit();
+ } else {
$db->rollback();
- $action='create';
- $_GET["origin"]=$_POST["origin"];
- $_GET["originid"]=$_POST["originid"];
- $mesgs[]=''.$object->error.'
';
+ $action = 'create';
+ $_GET ["origin"] = $_POST ["origin"];
+ $_GET ["originid"] = $_POST ["originid"];
+ $mesgs [] = '' . $object->error . '
';
}
-}
+}
// Add a new line
-else if (($action == 'addline' || $action == 'addline_predef') && $user->rights->facture->creer)
-{
+else if (($action == 'addline' || $action == 'addline_predef') && $user->rights->facture->creer) {
$langs->load('errors');
$error = 0;
-
+
// Set if we used free entry or predefined product
- if (GETPOST('addline_libre'))
- {
- $predef='';
- $idprod=0;
- $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
+ if (GETPOST('addline_libre')) {
+ $predef = '';
+ $idprod = 0;
+ $product_desc = (GETPOST('dp_desc') ? GETPOST('dp_desc') : '');
$price_ht = GETPOST('price_ht');
- $tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
+ $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
}
- if (GETPOST('addline_predefined'))
- {
- $predef=(($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
- $idprod=GETPOST('idprod', 'int');
- $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):''));
+ if (GETPOST('addline_predefined')) {
+ $predef = (($conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
+ $idprod = GETPOST('idprod', 'int');
+ $product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : ''));
$price_ht = '';
$tva_tx = '';
}
- if (GETPOST('usenewaddlineform')) { // TODO Remove this
- $idprod=GETPOST('idprod', 'int');
- $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):'')));
- $price_ht = GETPOST('price_ht');
- $tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
- }
- $qty = GETPOST('qty'.$predef);
- $remise_percent=GETPOST('remise_percent'.$predef);
-
- //Extrafields
+ if (GETPOST('usenewaddlineform')) { // TODO Remove this
+ $idprod = GETPOST('idprod', 'int');
+ $product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : (GETPOST('dp_desc') ? GETPOST('dp_desc') : '')));
+ $price_ht = GETPOST('price_ht');
+ $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
+ }
+ $qty = GETPOST('qty' . $predef);
+ $remise_percent = GETPOST('remise_percent' . $predef);
+
+ // Extrafields
$extrafieldsline = new ExtraFields($db);
- $extralabelsline =$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
- $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline,$predef);
- //Unset extrafield
- if (is_array($extralabelsline))
- {
+ $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+ $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
+ // Unset extrafield
+ if (is_array($extralabelsline)) {
// Get extra fields
foreach ($extralabelsline as $key => $value) {
- unset($_POST["options_".$key.$predef]);
+ unset($_POST ["options_" . $key . $predef]);
}
}
-
- if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && ($qty < 0))
- {
+
+ if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && ($qty < 0)) {
setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
+ $error ++;
}
- if (empty($idprod) && GETPOST('type') < 0)
- {
+ if (empty($idprod) && GETPOST('type') < 0) {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
- $error++;
+ $error ++;
}
- if ((empty($idprod) || GETPOST('usenewaddlineform')) && (!($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not ''
+ if ((empty($idprod) || GETPOST('usenewaddlineform')) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not ''
{
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
- $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
+ $error ++;
}
- if ($qty == '')
- {
+ if ($qty == '') {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
+ $error ++;
}
- if (empty($idprod) && empty($product_desc))
- {
+ if (empty($idprod) && empty($product_desc)) {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
- $error++;
+ $error ++;
}
-
- if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod)))
- {
- $ret=$object->fetch($id);
- if ($ret < 0)
- {
- dol_print_error($db,$object->error);
- exit;
+
+ if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) {
+ $ret = $object->fetch($id);
+ if ($ret < 0) {
+ dol_print_error($db, $object->error);
+ exit();
}
- $ret=$object->fetch_thirdparty();
-
+ $ret = $object->fetch_thirdparty();
+
// Clean parameters
- $date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
- $date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
- $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT');
-
+ $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
+ $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
+ $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
+
// Define special_code for special lines
- $special_code=0;
- //if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices
-
+ $special_code = 0;
+ // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices
+
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
// Ecrase $base_price_type par celui du produit
- if (! empty($idprod))
- {
+ if (! empty($idprod)) {
$prod = new Product($db);
$prod->fetch($idprod);
-
- $label = ((GETPOST('product_label') && GETPOST('product_label')!=$prod->label)?GETPOST('product_label'):'');
-
+
+ $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
+
// Update if prices fields are defined
- if (GETPOST('usenewaddlineform'))
- {
- $pu_ht=price2num($price_ht, 'MU');
- $pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
- $tva_npr=(preg_match('/\*/', $tva_tx)?1:0);
- $tva_tx=str_replace('*','', $tva_tx);
+ if (GETPOST('usenewaddlineform')) {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
+ $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
+ $tva_tx = str_replace('*', '', $tva_tx);
$desc = $product_desc;
- }
- else
- {
- $tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
- $tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
-
+ } else {
+ $tva_tx = get_default_tva($mysoc, $object->client, $prod->id);
+ $tva_npr = get_default_npr($mysoc, $object->client, $prod->id);
+
// We define price for product
- if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level))
- {
- $pu_ht = $prod->multiprices[$object->client->price_level];
- $pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
- $price_min = $prod->multiprices_min[$object->client->price_level];
- $price_base_type = $prod->multiprices_base_type[$object->client->price_level];
- }
- elseif (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
+ if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) {
+ $pu_ht = $prod->multiprices [$object->client->price_level];
+ $pu_ttc = $prod->multiprices_ttc [$object->client->price_level];
+ $price_min = $prod->multiprices_min [$object->client->price_level];
+ $price_base_type = $prod->multiprices_base_type [$object->client->price_level];
+ } elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
-
- $prodcustprice = new Productcustomerprice( $db );
-
- $filter = array (
- 't.fk_product' => $prod->id,
- 't.fk_soc'=> $object->client->id
- );
-
- $result = $prodcustprice->fetch_all( '', '', 0,0, $filter );
- if ($result)
- {
- if (count($prodcustprice->lines)>0)
- {
- $found=true;
- $pu_ht=price($prodcustprice->lines[0]->price);
- $pu_ttc=price($prodcustprice->lines[0]->price_ttc);
- $price_base_type=$prodcustprice->lines[0]->price_base_type;
- $prod->tva_tx=$prodcustprice->lines[0]->tva_tx;
+
+ $prodcustprice = new Productcustomerprice($db);
+
+ $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->client->id);
+
+ $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
+ if ($result) {
+ if (count($prodcustprice->lines) > 0) {
+ $found = true;
+ $pu_ht = price($prodcustprice->lines [0]->price);
+ $pu_ttc = price($prodcustprice->lines [0]->price_ttc);
+ $price_base_type = $prodcustprice->lines [0]->price_base_type;
+ $prod->tva_tx = $prodcustprice->lines [0]->tva_tx;
}
}
- }
- else
- {
+ } else {
$pu_ht = $prod->price;
$pu_ttc = $prod->price_ttc;
$price_min = $prod->price_min;
$price_base_type = $prod->price_base_type;
}
-
+
// if price ht is forced (ie: calculated by margin rate and cost price)
- if (!empty($price_ht))
- {
- $pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
- }
+ if (! empty($price_ht)) {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
+ }
// On reevalue prix selon taux tva car taux tva transaction peut etre different
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
- elseif ($tva_tx != $prod->tva_tx)
- {
- if ($price_base_type != 'HT')
- {
- $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
- }
- else
- {
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
+ elseif ($tva_tx != $prod->tva_tx) {
+ if ($price_base_type != 'HT') {
+ $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU');
+ } else {
+ $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
}
}
-
- $desc='';
-
+
+ $desc = '';
+
// Define output language
- if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
- {
+ if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
$outputlangs = $langs;
- $newlang='';
- if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if (empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if (empty($newlang) && GETPOST('lang_id'))
+ $newlang = GETPOST('lang_id');
+ if (empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $desc = (! empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
- }
- else
- {
+
+ $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
+ } else {
$desc = $prod->description;
}
-
- $desc=dol_concatdesc($desc,$product_desc);
-
+
+ $desc = dol_concatdesc($desc, $product_desc);
+
// Add custom code and origin country into description
- if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
- {
- $tmptxt='(';
- if (! empty($prod->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
- if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - ';
- if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0);
- $tmptxt.=')';
- $desc= dol_concatdesc($desc, $tmptxt);
+ if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
+ $tmptxt = '(';
+ if (! empty($prod->customcode))
+ $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
+ if (! empty($prod->customcode) && ! empty($prod->country_code))
+ $tmptxt .= ' - ';
+ if (! empty($prod->country_code))
+ $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
+ $tmptxt .= ')';
+ $desc = dol_concatdesc($desc, $tmptxt);
}
}
-
+
$type = $prod->type;
+ } else {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
+ $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
+ $tva_tx = str_replace('*', '', $tva_tx);
+ $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
+ $desc = $product_desc;
+ $type = GETPOST('type');
}
- else
- {
- $pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
- $tva_npr = (preg_match('/\*/', $tva_tx)?1:0);
- $tva_tx = str_replace('*', '', $tva_tx);
- $label = (GETPOST('product_label')?GETPOST('product_label'):'');
- $desc = $product_desc;
- $type = GETPOST('type');
- }
-
+
// Margin
- $fournprice=price2num(GETPOST('fournprice'.$predef)?GETPOST('fournprice'.$predef):'');
- $buyingprice=price2num(GETPOST('buying_price'.$predef)?GETPOST('buying_price'.$predef):'');
-
+ $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
+ $buyingprice = price2num(GETPOST('buying_price' . $predef) ? GETPOST('buying_price' . $predef) : '');
+
// Local Taxes
- $localtax1_tx= get_localtax($tva_tx, 1, $object->client);
- $localtax2_tx= get_localtax($tva_tx, 2, $object->client);
-
- $info_bits=0;
- if ($tva_npr) $info_bits |= 0x01;
-
- if (! empty($price_min) && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min)))
- {
- $mesg = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency));
+ $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
+ $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
+
+ $info_bits = 0;
+ if ($tva_npr)
+ $info_bits |= 0x01;
+
+ if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) {
+ $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
setEventMessage($mesg, 'errors');
- }
- else
- {
+ } else {
// Insert line
- $result = $object->addline(
- $desc,
- $pu_ht,
- $qty,
- $tva_tx,
- $localtax1_tx,
- $localtax2_tx,
- $idprod,
- $remise_percent,
- $date_start,
- $date_end,
- 0,
- $info_bits,
- '',
- $price_base_type,
- $pu_ttc,
- $type,
- -1,
- $special_code,
- '',
- 0,
- GETPOST('fk_parent_line'),
- $fournprice,
- $buyingprice,
- $label,
- $array_option
- );
-
- if ($result > 0)
- {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
+ $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, - 1, $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_option);
+
+ if ($result > 0) {
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;
- $newlang=GETPOST('lang_id','alpha');
- if (! empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = GETPOST('lang_id', 'alpha');
+ if (! empty($conf->global->MAIN_MULTILANGS) && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $ret=$object->fetch($id); // Reload to get new records
+
+ $ret = $object->fetch($id); // Reload to get new records
facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
-
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['remise_percent']);
- unset($_POST['price_ht']);
- unset($_POST['price_ttc']);
- unset($_POST['tva_tx']);
- unset($_POST['product_ref']);
- unset($_POST['product_label']);
- unset($_POST['product_desc']);
- unset($_POST['fournprice']);
- unset($_POST['buying_price']);
- unset($_POST['np_marginRate']);
- unset($_POST['np_markRate']);
- unset($_POST['dp_desc']);
-
- unset($_POST['idprod']);
- unset($_POST['qty_predef']);
- unset($_POST['remise_percent_predef']);
- unset($_POST['fournprice_predef']);
- unset($_POST['buying_price_predef']);
- unset($_POST['np_marginRate_predef']);
- unset($_POST['np_markRate_predef']);
- unset($_POST['np_desc']);
- }
- else
- {
+
+ unset($_POST ['qty']);
+ unset($_POST ['type']);
+ unset($_POST ['remise_percent']);
+ unset($_POST ['price_ht']);
+ unset($_POST ['price_ttc']);
+ unset($_POST ['tva_tx']);
+ unset($_POST ['product_ref']);
+ unset($_POST ['product_label']);
+ unset($_POST ['product_desc']);
+ unset($_POST ['fournprice']);
+ unset($_POST ['buying_price']);
+ unset($_POST ['np_marginRate']);
+ unset($_POST ['np_markRate']);
+ unset($_POST ['dp_desc']);
+
+ unset($_POST ['idprod']);
+ unset($_POST ['qty_predef']);
+ unset($_POST ['remise_percent_predef']);
+ unset($_POST ['fournprice_predef']);
+ unset($_POST ['buying_price_predef']);
+ unset($_POST ['np_marginRate_predef']);
+ unset($_POST ['np_markRate_predef']);
+ unset($_POST ['np_desc']);
+ } else {
setEventMessage($object->error, 'errors');
}
-
- $action='';
+
+ $action = '';
}
}
-}
+}
-elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel'))
-{
- if (! $object->fetch($id) > 0) dol_print_error($db);
+elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel')) {
+ if (! $object->fetch($id) > 0)
+ dol_print_error($db);
$object->fetch_thirdparty();
-
+
// Clean parameters
- $date_start='';
- $date_end='';
- $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
- $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
- $description=dol_htmlcleanlastbr(GETPOST('product_desc'));
- $pu_ht=GETPOST('price_ht');
- $vat_rate=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
-
+ $date_start = '';
+ $date_end = '';
+ $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
+ $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
+ $description = dol_htmlcleanlastbr(GETPOST('product_desc'));
+ $pu_ht = GETPOST('price_ht');
+ $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
+
// Define info_bits
- $info_bits=0;
- if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01;
-
- // Define vat_rate
- $vat_rate=str_replace('*','',$vat_rate);
- $localtax1_rate=get_localtax($vat_rate,1,$object->client);
- $localtax2_rate=get_localtax($vat_rate,2,$object->client);
-
+ $info_bits = 0;
+ if (preg_match('/\*/', $vat_rate))
+ $info_bits |= 0x01;
+
+ // Define vat_rate
+ $vat_rate = str_replace('*', '', $vat_rate);
+ $localtax1_rate = get_localtax($vat_rate, 1, $object->client);
+ $localtax2_rate = get_localtax($vat_rate, 2, $object->client);
+
// Add buying price
- $fournprice=price2num(GETPOST('fournprice')?GETPOST('fournprice'):'');
- $buyingprice=price2num(GETPOST('buying_price')?GETPOST('buying_price'):'');
-
- //Extrafields
+ $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
+ $buyingprice = price2num(GETPOST('buying_price') ? GETPOST('buying_price') : '');
+
+ // Extrafields
$extrafieldsline = new ExtraFields($db);
- $extralabelsline =$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+ $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
- //Unset extrafield
- if (is_array($extralabelsline))
- {
+ // Unset extrafield
+ if (is_array($extralabelsline)) {
// Get extra fields
- foreach ($extralabelsline as $key => $value)
- {
- unset($_POST["options_".$key]);
+ foreach ($extralabelsline as $key => $value) {
+ unset($_POST ["options_" . $key]);
}
}
-
-
+
// Check minimum price
$productid = GETPOST('productid', 'int');
- if (! empty($productid))
- {
+ if (! empty($productid)) {
$product = new Product($db);
$product->fetch($productid);
-
- $type=$product->type;
-
+
+ $type = $product->type;
+
$price_min = $product->price_min;
if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level))
- $price_min = $product->multiprices_min[$object->client->price_level];
-
- $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label'):'');
-
+ $price_min = $product->multiprices_min [$object->client->price_level];
+
+ $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
+
// Check price is not lower than minimum (check is done only for standard or replacement invoices)
- if (($object->type == 0 || $object->type == 1) && $price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
- {
- setEventMessage($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)), 'errors');
- $error++;
+ if (($object->type == 0 || $object->type == 1) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
+ setEventMessage($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), 'errors');
+ $error ++;
}
- }
- else
- {
+ } else {
$type = GETPOST('type');
- $label = (GETPOST('product_label') ? GETPOST('product_label'):'');
-
+ $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
+
// Check parameters
if (GETPOST('type') < 0) {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
- $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), 'errors');
+ $error ++;
}
}
-
+
// Update line
- if (! $error)
- {
- $result = $object->updateline(
- GETPOST('lineid'),
- $description,
- $pu_ht,
- GETPOST('qty'),
- GETPOST('remise_percent'),
- $date_start,
- $date_end,
- $vat_rate,
- $localtax1_rate,
- $localtax2_rate,
- 'HT',
- $info_bits,
- $type,
- GETPOST('fk_parent_line'),
- 0,
- $fournprice,
- $buyingprice,
- $label,
- 0,
- $array_option
- );
-
- if ($result >= 0)
- {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
+ if (! $error) {
+ $result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, 0, $array_option);
+
+ if ($result >= 0) {
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
+ $newlang = GETPOST('lang_id');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $ret=$object->fetch($id); // Reload to get new records
+
+ $ret = $object->fetch($id); // Reload to get new records
facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
-
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['productid']);
- unset($_POST['remise_percent']);
- unset($_POST['price_ht']);
- unset($_POST['price_ttc']);
- unset($_POST['tva_tx']);
- unset($_POST['product_ref']);
- unset($_POST['product_label']);
- unset($_POST['product_desc']);
- unset($_POST['fournprice']);
- unset($_POST['buying_price']);
- }
- else
- {
+
+ unset($_POST ['qty']);
+ unset($_POST ['type']);
+ unset($_POST ['productid']);
+ unset($_POST ['remise_percent']);
+ unset($_POST ['price_ht']);
+ unset($_POST ['price_ttc']);
+ unset($_POST ['tva_tx']);
+ unset($_POST ['product_ref']);
+ unset($_POST ['product_label']);
+ unset($_POST ['product_desc']);
+ unset($_POST ['fournprice']);
+ unset($_POST ['buying_price']);
+ } else {
setEventMessage($object->error, 'errors');
}
}
-}
+}
-else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['cancel'] == $langs->trans('Cancel'))
-{
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); // Pour reaffichage de la fiche en cours d'edition
- exit;
-}
+else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST ['cancel'] == $langs->trans('Cancel')) {
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $id); // Pour reaffichage de la fiche en cours d'edition
+ exit();
+}
// Modify line position (up)
-else if ($action == 'up' && $user->rights->facture->creer)
-{
+else if ($action == 'up' && $user->rights->facture->creer) {
$object->fetch($id);
$object->fetch_thirdparty();
- $object->line_up($_GET['rowid']);
-
+ $object->line_up($_GET ['rowid']);
+
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
-
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
- exit;
-}
-// Modify line position (down)
-else if ($action == 'down' && $user->rights->facture->creer)
-{
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+ facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $object->id . '#' . $_GET ['rowid']);
+ exit();
+} // Modify line position (down)
+else if ($action == 'down' && $user->rights->facture->creer) {
$object->fetch($id);
$object->fetch_thirdparty();
- $object->line_down($_GET['rowid']);
-
+ $object->line_down($_GET ['rowid']);
+
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
-
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
- exit;
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+ facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $object->id . '#' . $_GET ['rowid']);
+ exit();
}
// Link invoice to order
-if (GETPOST('linkedOrder'))
-{
+if (GETPOST('linkedOrder')) {
$object->fetch($id);
$object->fetch_thirdparty();
- $result=$object->add_object_linked('commande',GETPOST('linkedOrder'));
+ $result = $object->add_object_linked('commande', GETPOST('linkedOrder'));
}
-
/*
* Add file in email form
*/
-if (GETPOST('addfile'))
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+if (GETPOST('addfile')) {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
// Set tmp user directory
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir_tmp = $vardir.'/temp';
-
- dol_add_file_process($upload_dir_tmp,0,0);
- $action='presend';
+ $vardir = $conf->user->dir_output . "/" . $user->id;
+ $upload_dir_tmp = $vardir . '/temp';
+
+ dol_add_file_process($upload_dir_tmp, 0, 0);
+ $action = 'presend';
}
/*
* Remove file in email form
*/
-if (! empty($_POST['removedfile']))
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+if (! empty($_POST ['removedfile'])) {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
// Set tmp user directory
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir_tmp = $vardir.'/temp';
-
+ $vardir = $conf->user->dir_output . "/" . $user->id;
+ $upload_dir_tmp = $vardir . '/temp';
+
// TODO Delete only files that was uploaded from email form
- dol_remove_file_process($_POST['removedfile'],0);
- $action='presend';
+ dol_remove_file_process($_POST ['removedfile'], 0);
+ $action = 'presend';
}
/*
* Send mail
*/
-if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
-{
+if (($action == 'send' || $action == 'relance') && ! $_POST ['addfile'] && ! $_POST ['removedfile'] && ! $_POST ['cancel']) {
$langs->load('mails');
-
- $actiontypecode='';$subject='';$actionmsg='';$actionmsg2='';
-
- $result=$object->fetch($id);
- $result=$object->fetch_thirdparty();
-
- if ($result > 0)
- {
- // $ref = dol_sanitizeFileName($object->ref);
- // $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
-
- // if (is_readable($file))
- // {
- if ($_POST['sendto'])
- {
+
+ $actiontypecode = '';
+ $subject = '';
+ $actionmsg = '';
+ $actionmsg2 = '';
+
+ $result = $object->fetch($id);
+ $result = $object->fetch_thirdparty();
+
+ if ($result > 0) {
+ // $ref = dol_sanitizeFileName($object->ref);
+ // $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+
+ // if (is_readable($file))
+ // {
+ if ($_POST ['sendto']) {
// Le destinataire a ete fourni via le champ libre
- $sendto = $_POST['sendto'];
+ $sendto = $_POST ['sendto'];
$sendtoid = 0;
- }
- elseif ($_POST['receiver'] != '-1')
- {
+ } elseif ($_POST ['receiver'] != '-1') {
// Recipient was provided from combo list
- if ($_POST['receiver'] == 'thirdparty') // Id of third party
+ if ($_POST ['receiver'] == 'thirdparty') // Id of third party
{
$sendto = $object->client->email;
$sendtoid = 0;
- }
- else // Id du contact
+ } else // Id du contact
{
- $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
- $sendtoid = $_POST['receiver'];
+ $sendto = $object->client->contact_get_property($_POST ['receiver'], 'email');
+ $sendtoid = $_POST ['receiver'];
}
}
-
- if (dol_strlen($sendto))
- {
+
+ if (dol_strlen($sendto)) {
$langs->load("commercial");
-
- $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
- $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
- $message = $_POST['message'];
- $sendtocc = $_POST['sendtocc'];
- $deliveryreceipt = $_POST['deliveryreceipt'];
-
- if ($action == 'send')
- {
- if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
- else $subject = $langs->transnoentities('Bill').' '.$object->ref;
- $actiontypecode='AC_FAC';
- $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
- if ($message)
- {
- $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
- $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
- $actionmsg.=$message;
- }
- //$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
- }
- if ($action == 'relance')
- {
- if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
- else $subject = $langs->transnoentities('Relance facture '.$object->ref);
- $actiontypecode='AC_FAC';
- $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
+
+ $from = $_POST ['fromname'] . ' <' . $_POST ['frommail'] . '>';
+ $replyto = $_POST ['replytoname'] . ' <' . $_POST ['replytomail'] . '>';
+ $message = $_POST ['message'];
+ $sendtocc = $_POST ['sendtocc'];
+ $deliveryreceipt = $_POST ['deliveryreceipt'];
+
+ if ($action == 'send') {
+ if (dol_strlen($_POST ['subject']))
+ $subject = $_POST ['subject'];
+ else
+ $subject = $langs->transnoentities('Bill') . ' ' . $object->ref;
+ $actiontypecode = 'AC_FAC';
+ $actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto . ".\n";
if ($message) {
- $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
- $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
- $actionmsg.=$message;
+ $actionmsg .= $langs->transnoentities('MailTopic') . ": " . $subject . "\n";
+ $actionmsg .= $langs->transnoentities('TextUsedInTheMessageBody') . ":\n";
+ $actionmsg .= $message;
}
- //$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+ // $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
}
-
+ if ($action == 'relance') {
+ if (dol_strlen($_POST ['subject']))
+ $subject = $_POST ['subject'];
+ else
+ $subject = $langs->transnoentities('Relance facture ' . $object->ref);
+ $actiontypecode = 'AC_FAC';
+ $actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto . ".\n";
+ if ($message) {
+ $actionmsg .= $langs->transnoentities('MailTopic') . ": " . $subject . "\n";
+ $actionmsg .= $langs->transnoentities('TextUsedInTheMessageBody') . ":\n";
+ $actionmsg .= $message;
+ }
+ // $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+ }
+
// Create form object
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
-
- $attachedfiles=$formmail->get_attached_files();
- $filepath = $attachedfiles['paths'];
- $filename = $attachedfiles['names'];
- $mimetype = $attachedfiles['mimes'];
-
+
+ $attachedfiles = $formmail->get_attached_files();
+ $filepath = $attachedfiles ['paths'];
+ $filename = $attachedfiles ['names'];
+ $mimetype = $attachedfiles ['mimes'];
+
// Send mail
- require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
- $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
- if ($mailfile->error)
- {
- $mesgs[]=''.$mailfile->error.'
';
- }
- else
- {
- $result=$mailfile->sendfile();
- if ($result)
- {
- $error=0;
-
+ require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
+ $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, - 1);
+ if ($mailfile->error) {
+ $mesgs [] = '' . $mailfile->error . '
';
+ } else {
+ $result = $mailfile->sendfile();
+ if ($result) {
+ $error = 0;
+
// Initialisation donnees
- $object->sendtoid = $sendtoid;
- $object->actiontypecode = $actiontypecode;
- $object->actionmsg = $actionmsg; // Long text
- $object->actionmsg2 = $actionmsg2; // Short text
- $object->fk_element = $object->id;
- $object->elementtype = $object->element;
-
+ $object->sendtoid = $sendtoid;
+ $object->actiontypecode = $actiontypecode;
+ $object->actionmsg = $actionmsg; // Long text
+ $object->actionmsg2 = $actionmsg2; // Short text
+ $object->fk_element = $object->id;
+ $object->elementtype = $object->element;
+
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
- $interface=new Interfaces($db);
- $result=$interface->run_triggers('BILL_SENTBYMAIL',$object,$user,$langs,$conf);
+ $interface = new Interfaces($db);
+ $result = $interface->run_triggers('BILL_SENTBYMAIL', $object, $user, $langs, $conf);
if ($result < 0) {
- $error++; $this->errors=$interface->errors;
+ $error ++;
+ $this->errors = $interface->errors;
}
// Fin appel triggers
-
- if ($error)
- {
+
+ if ($error) {
dol_print_error($db);
- }
- else
- {
+ } else {
// Redirect here
// This avoid sending mail twice if going out and then back to page
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
+ $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
setEventMessage($mesg);
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id);
- exit;
+ header('Location: ' . $_SERVER ["PHP_SELF"] . '?facid=' . $object->id);
+ exit();
}
- }
- else
- {
+ } else {
$langs->load("other");
- $mesg='';
- if ($mailfile->error)
- {
- $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
- $mesg.='
'.$mailfile->error;
+ $mesg = '
';
+ if ($mailfile->error) {
+ $mesg .= $langs->trans('ErrorFailedToSendMail', $from, $sendto);
+ $mesg .= ' ' . $mailfile->error;
+ } else {
+ $mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
}
- else
- {
- $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
- }
- $mesg.='
';
- $mesgs[]=$mesg;
+ $mesg .= '
';
+ $mesgs [] = $mesg;
}
}
/* }
@@ -1823,184 +1546,163 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$mesgs[]=''.$langs->trans('ErrorMailRecipientIsEmpty').'
';
dol_syslog('Recipient email is empty');
}*/
- }
- else
- {
+ } else {
$langs->load("errors");
- $mesgs[]=''.$langs->trans('ErrorCantReadFile',$file).'
';
- dol_syslog('Failed to read file: '.$file);
+ $mesgs [] = '' . $langs->trans('ErrorCantReadFile', $file) . '
';
+ dol_syslog('Failed to read file: ' . $file);
}
- }
- else
- {
+ } else {
$langs->load("other");
- $mesgs[]=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
';
+ $mesgs [] = '' . $langs->trans('ErrorFailedToReadEntity', $langs->trans("Invoice")) . '
';
dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
}
-
+
$action = 'presend';
-}
+}
/*
* Generate document
*/
-else if ($action == 'builddoc') // En get ou en post
+else if ($action == 'builddoc') // En get ou en post
{
$object->fetch($id);
$object->fetch_thirdparty();
-
+
// Save last template used to generate document
- if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
- if (GETPOST('fk_bank')) $object->fk_bank=GETPOST('fk_bank');
-
- // Define output language
+ if (GETPOST('model'))
+ $object->setDocModel($user, GETPOST('model', 'alpha'));
+ if (GETPOST('fk_bank'))
+ $object->fk_bank = GETPOST('fk_bank');
+
+ // Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
+ $newlang = GETPOST('lang_id');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
+ $result = facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($result <= 0) {
+ dol_print_error($db, $result);
+ exit();
}
-}
+}
// Remove file in doc form
-else if ($action == 'remove_file')
-{
- if ($object->fetch($id))
- {
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
+else if ($action == 'remove_file') {
+ if ($object->fetch($id)) {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+
$object->fetch_thirdparty();
-
+
$langs->load("other");
$upload_dir = $conf->facture->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
- $ret=dol_delete_file($file,0,0,0,$object);
- if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
- else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
- $action='';
+ $ret = dol_delete_file($file, 0, 0, 0, $object);
+ if ($ret)
+ setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else
+ setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
+ $action = '';
}
-}
+}
// Print file
-else if ($action == 'print_file' AND $user->rights->printipp->read)
-{
- require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
- $printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD);
- $printer->print_file(GETPOST('file','alpha'),GETPOST('printer','alpha'));
- setEventMessage($langs->trans("FileWasSentToPrinter", GETPOST('file')));
- $action='';
+else if ($action == 'print_file' and $user->rights->printipp->read) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/dolprintipp.class.php';
+ $printer = new dolPrintIPP($db, $conf->global->PRINTIPP_HOST, $conf->global->PRINTIPP_PORT, $user->login, $conf->global->PRINTIPP_USER, $conf->global->PRINTIPP_PASSWORD);
+ $printer->print_file(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha'));
+ setEventMessage($langs->trans("FileWasSentToPrinter", GETPOST('file')));
+ $action = '';
}
-if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer)
-{
- if ($action == 'addcontact')
- {
+if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer) {
+ if ($action == 'addcontact') {
$result = $object->fetch($id);
-
- if ($result > 0 && $id > 0)
- {
+
+ if ($result > 0 && $id > 0) {
$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
- $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
+ $result = $object->add_contact($contactid, $_POST ["type"], $_POST ["source"]);
}
-
- if ($result >= 0)
- {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- }
- else
- {
- if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
+
+ if ($result >= 0) {
+ header("Location: " . $_SERVER ['PHP_SELF'] . "?id=" . $object->id);
+ exit();
+ } else {
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
- $mesgs[] = ''.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
';
- }
- else
- {
- $mesgs[] = ''.$object->error.'
';
+ $mesgs [] = '' . $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType") . '
';
+ } else {
+ $mesgs [] = '' . $object->error . '
';
}
}
- }
+ }
// bascule du statut d'un contact
- else if ($action == 'swapstatut')
- {
- if ($object->fetch($id))
- {
- $result=$object->swapContactStatus(GETPOST('ligne'));
- }
- else
- {
+ else if ($action == 'swapstatut') {
+ if ($object->fetch($id)) {
+ $result = $object->swapContactStatus(GETPOST('ligne'));
+ } else {
dol_print_error($db);
}
- }
+ }
// Efface un contact
- else if ($action == 'deletecontact')
- {
+ else if ($action == 'deletecontact') {
$object->fetch($id);
$result = $object->delete_contact($lineid);
-
- if ($result >= 0)
- {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- }
- else {
+
+ if ($result >= 0) {
+ header("Location: " . $_SERVER ['PHP_SELF'] . "?id=" . $object->id);
+ exit();
+ } else {
dol_print_error($db);
}
}
}
-if ($action == 'update_extras')
-{
+if ($action == 'update_extras') {
// Fill array 'array_options' with data from add form
- $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
- if ($ret < 0) $error++;
-
- if (! $error)
- {
+ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+ $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
+ if ($ret < 0)
+ $error ++;
+
+ if (! $error) {
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('invoicedao'));
- $parameters=array('id'=>$object->id);
- $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
- if (empty($reshook))
- {
- $result=$object->insertExtraFields();
- if ($result < 0)
- {
- $error++;
+ $parameters = array('id' => $object->id);
+ $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by
+ // some hooks
+ if (empty($reshook)) {
+ $result = $object->insertExtraFields();
+ if ($result < 0) {
+ $error ++;
}
- }
- else if ($reshook < 0) $error++;
+ } else if ($reshook < 0)
+ $error ++;
}
-
- if ($error) $action = 'edit_extras';
+
+ if ($error)
+ $action = 'edit_extras';
}
-
/*
* View
*/
$form = new Form($db);
-$formother=new FormOther($db);
+$formother = new FormOther($db);
$formfile = new FormFile($db);
-$bankaccountstatic=new Account($db);
-$now=dol_now();
+$bankaccountstatic = new Account($db);
+$now = dol_now();
-llxHeader('',$langs->trans('Bill'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
+llxHeader('', $langs->trans('Bill'), 'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
print '
';
-
-/*********************************************************************
+/**
+ * *******************************************************************
*
* Mode creation
*
- **********************************************************************/
-if ($action == 'create')
-{
- $facturestatic=new Facture($db);
- $extralabels=$extrafields->fetch_name_optionals_label($facturestatic->table_element);
-
+ * ********************************************************************
+ */
+if ($action == 'create') {
+ $facturestatic = new Facture($db);
+ $extralabels = $extrafields->fetch_name_optionals_label($facturestatic->table_element);
+
print_fiche_titre($langs->trans('NewBill'));
-
+
$soc = new Societe($db);
- if ($socid>0) $res=$soc->fetch($socid);
-
- if (! empty($origin) && ! empty($originid))
- {
+ if ($socid > 0)
+ $res = $soc->fetch($socid);
+
+ if (! empty($origin) && ! empty($originid)) {
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin;
- if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs))
- {
- $element = $regs[1];
- $subelement = $regs[2];
+ if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
+ $element = $regs [1];
+ $subelement = $regs [2];
}
-
- if ($element == 'project')
- {
- $projectid=$originid;
- }
- else
- {
+
+ if ($element == 'project') {
+ $projectid = $originid;
+ } else {
// For compatibility
- if ($element == 'order' || $element == 'commande') {
+ if ($element == 'order' || $element == 'commande') {
$element = $subelement = 'commande';
}
- if ($element == 'propal') {
- $element = 'comm/propal'; $subelement = 'propal';
+ if ($element == 'propal') {
+ $element = 'comm/propal';
+ $subelement = 'propal';
}
if ($element == 'contract') {
$element = $subelement = 'contrat';
@@ -2057,1951 +1756,1769 @@ if ($action == 'create')
if ($element == 'shipping') {
$element = $subelement = 'expedition';
}
-
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
-
+
+ dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
+
$classname = ucfirst($subelement);
$objectsrc = new $classname($db);
$objectsrc->fetch($originid);
- if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines();
+ if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
+ $objectsrc->fetch_lines();
$objectsrc->fetch_thirdparty();
-
- $projectid = (! empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
- $ref_client = (! empty($objectsrc->ref_client)?$objectsrc->ref_client:'');
- $ref_int = (! empty($objectsrc->ref_int)?$objectsrc->ref_int:'');
-
+
+ $projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
+ $ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
+ $ref_int = (! empty($objectsrc->ref_int) ? $objectsrc->ref_int : '');
+
$soc = $objectsrc->thirdparty;
- $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
- $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
- $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0));
- $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0));
- $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
-
- //Replicate extrafields
+ $cond_reglement_id = (! empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (! empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 1));
+ $mode_reglement_id = (! empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (! empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
+ $remise_percent = (! empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (! empty($soc->remise_percent) ? $soc->remise_percent : 0));
+ $remise_absolue = (! empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (! empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
+ $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : 0;
+
+ // Replicate extrafields
$objectsrc->fetch_optionals($originid);
- $object->array_options=$objectsrc->array_options;
+ $object->array_options = $objectsrc->array_options;
}
+ } else {
+ $cond_reglement_id = $soc->cond_reglement_id;
+ $mode_reglement_id = $soc->mode_reglement_id;
+ $remise_percent = $soc->remise_percent;
+ $remise_absolue = 0;
+ $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : 0;
}
- else
- {
- $cond_reglement_id = $soc->cond_reglement_id;
- $mode_reglement_id = $soc->mode_reglement_id;
- $remise_percent = $soc->remise_percent;
- $remise_absolue = 0;
- $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
- }
- $absolute_discount=$soc->getAvailableDiscounts();
-
-
- if (! empty($conf->use_javascript_ajax))
- {
+ $absolute_discount = $soc->getAvailableDiscounts();
+
+ if (! empty($conf->use_javascript_ajax)) {
print ajax_combobox('fac_replacement');
print ajax_combobox('fac_avoir');
}
-
- print '';
- print ' ';
+
+ print ' ';
+ print ' ';
print ' ';
if ($soc->id > 0)
- print ' ' ."\n";
+ print ' ' . "\n";
print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
-
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+
print '';
-
+
// Ref
- print ''.$langs->trans('Ref').' '.$langs->trans('Draft').' ';
-
+ print '' . $langs->trans('Ref') . ' ' . $langs->trans('Draft') . ' ';
+
// Thirdparty
- print ''.$langs->trans('Customer').' ';
- if($soc->id > 0)
- {
+ print '' . $langs->trans('Customer') . ' ';
+ if ($soc->id > 0) {
print '';
print $soc->getNomUrl(1);
- print ' ';
+ print ' ';
// Outstanding Bill
- $outstandigBills=$soc->get_OutstandingBill();
- print ' ('.$langs->trans('CurrentOutstandingBill').': ';
- print price($outstandigBills,'',$langs,0,0,-1,$conf->currency);
- if ($soc->outstanding_limit != '')
- {
- if ($outstandigBills > $soc->outstanding_limit) print img_warning($langs->trans("OutstandingBillReached"));
- print ' / '.price($soc->outstanding_limit);
+ $outstandigBills = $soc->get_OutstandingBill();
+ print ' (' . $langs->trans('CurrentOutstandingBill') . ': ';
+ print price($outstandigBills, '', $langs, 0, 0, - 1, $conf->currency);
+ if ($soc->outstanding_limit != '') {
+ if ($outstandigBills > $soc->outstanding_limit)
+ print img_warning($langs->trans("OutstandingBillReached"));
+ print ' / ' . price($soc->outstanding_limit);
}
print ')';
print ' ';
- }
- else
- {
+ } else {
print '';
- print $form->select_company('','socid','s.client = 1 OR s.client = 3',1);
+ print $form->select_company('', 'socid', 's.client = 1 OR s.client = 3', 1);
print ' ';
}
- print ''."\n";
-
+ print '' . "\n";
+
// Predefined invoices
- if (empty($origin) && empty($originid) && $socid > 0)
- {
+ if (empty($origin) && empty($originid) && $socid > 0) {
$sql = 'SELECT r.rowid, r.titre, r.total_ttc';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as r';
- $sql.= ' WHERE r.fk_soc = '.$soc->id;
-
- $resql=$db->query($sql);
- if ($resql)
- {
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r';
+ $sql .= ' WHERE r.fk_soc = ' . $soc->id;
+
+ $resql = $db->query($sql);
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
-
- if ($num > 0)
- {
- print ''.$langs->trans('CreateFromRepeatableInvoice').' ';
+
+ if ($num > 0) {
+ print ' ' . $langs->trans('CreateFromRepeatableInvoice') . ' ';
print '';
print ' ';
- while ($i < $num)
- {
+ while ($i < $num) {
$objp = $db->fetch_object($resql);
- print 'rowid) print ' selected="selected"';
- print '>'.$objp->titre.' ('.price($objp->total_ttc).' '.$langs->trans("TTC").') ';
- $i++;
+ print 'rowid)
+ print ' selected="selected"';
+ print '>' . $objp->titre . ' (' . price($objp->total_ttc) . ' ' . $langs->trans("TTC") . ') ';
+ $i ++;
}
print ' ';
}
$db->free($resql);
- }
- else
- {
+ } else {
dol_print_error($db);
}
}
-
+
// Type de facture
- $facids=$facturestatic->list_replacable_invoices($soc->id);
- if ($facids < 0)
- {
- dol_print_error($db,$facturestatic);
- exit;
+ $facids = $facturestatic->list_replacable_invoices($soc->id);
+ if ($facids < 0) {
+ dol_print_error($db, $facturestatic);
+ exit();
}
- $options="";
- foreach ($facids as $facparam)
- {
- $options.=''.$facparam['ref'];
- $options.=' ('.$facturestatic->LibStatut(0,$facparam['status']).')';
- $options.=' ';
+ $options = "";
+ foreach ($facids as $facparam) {
+ $options .= 'LibStatut(0, $facparam ['status']) . ')';
+ $options .= ' ';
}
-
- $facids=$facturestatic->list_qualified_avoir_invoices($soc->id);
- if ($facids < 0)
- {
- dol_print_error($db,$facturestatic);
- exit;
+
+ $facids = $facturestatic->list_qualified_avoir_invoices($soc->id);
+ if ($facids < 0) {
+ dol_print_error($db, $facturestatic);
+ exit();
}
- $optionsav="";
- $newinvoice_static=new Facture($db);
- foreach ($facids as $key => $valarray)
- {
- $newinvoice_static->id=$key;
- $newinvoice_static->ref=$valarray['ref'];
- $newinvoice_static->statut=$valarray['status'];
- $newinvoice_static->type=$valarray['type'];
- $newinvoice_static->paye=$valarray['paye'];
-
- $optionsav.='';
- $optionsav.=$newinvoice_static->ref;
- $optionsav.=' ('.$newinvoice_static->getLibStatut(1,$valarray['paymentornot']).')';
- $optionsav.=' ';
+ $optionsav = "";
+ $newinvoice_static = new Facture($db);
+ foreach ($facids as $key => $valarray) {
+ $newinvoice_static->id = $key;
+ $newinvoice_static->ref = $valarray ['ref'];
+ $newinvoice_static->statut = $valarray ['status'];
+ $newinvoice_static->type = $valarray ['type'];
+ $newinvoice_static->paye = $valarray ['paye'];
+
+ $optionsav .= 'ref;
+ $optionsav .= ' (' . $newinvoice_static->getLibStatut(1, $valarray ['paymentornot']) . ')';
+ $optionsav .= ' ';
}
-
- print ''.$langs->trans('Type').' ';
- print ''."\n";
-
+
+ print '' . $langs->trans('Type') . ' ';
+ print '' . "\n";
+
// Standard invoice
print '';
- print ' ';
+ print ' ';
print ' ';
- $desc=$form->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
+ $desc = $form->textwithpicto($langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1);
print $desc;
- print ' '."\n";
-
+ print '' . "\n";
+
// Proforma
- if (! empty($conf->global->FACTURE_USE_PROFORMAT))
- {
+ if (! empty($conf->global->FACTURE_USE_PROFORMAT)) {
print '';
- print ' ';
+ print ' ';
print ' ';
- $desc=$form->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1);
+ $desc = $form->textwithpicto($langs->trans("InvoiceProForma"), $langs->transnoentities("InvoiceProFormaDesc"), 1);
print $desc;
- print ' '."\n";
+ print '' . "\n";
}
-
- if ((empty($origin)) || ((($origin=='propal') || ($origin=='commande')) && (!empty($originid))))
- {
+
+ if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid)))) {
// Deposit
print '';
- print ' ';
+ print ' ';
print ' ';
- $desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1);
- print ''.$desc.' ';
- if (($origin=='propal') || ($origin=='commande'))
- {
+ $desc = $form->textwithpicto($langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1);
+ print '' . $desc . ' ';
+ if (($origin == 'propal') || ($origin == 'commande')) {
print '';
- $arraylist=array('amount'=>'FixAmount','variable'=>'VarAmount');
- print $form->selectarray('typedeposit',$arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1);
+ $arraylist = array('amount' => 'FixAmount','variable' => 'VarAmount');
+ print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1);
print ' ';
- print ''.$langs->trans('Value').': ';
+ print ' ' . $langs->trans('Value') . ': ';
}
print '
';
- print ' '."\n";
+ print '' . "\n";
}
-
- if ($socid > 0)
- {
+
+ if ($socid > 0) {
// Replacement
print '';
- print ' ';
print ' ';
- $text=$langs->trans("InvoiceReplacementAsk").' ';
- $text.='';
- if ($options)
- {
- $text.=' ';
- $text.=$options;
+ $text = $langs->trans("InvoiceReplacementAsk") . ' ';
+ $text .= 'trans("NoReplacableInvoice") . '';
}
- else
- {
- $text.=''.$langs->trans("NoReplacableInvoice").' ';
- }
- $text.=' ';
- $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1);
+ $text .= ' ';
+ $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1);
print $desc;
- print ' '."\n";
+ print '' . "\n";
}
-
- if (empty($origin) && $socid > 0)
- {
+
+ if (empty($origin) && $socid > 0) {
// Credit note
print '';
- print ' ';
print ' ';
- $text=$langs->transnoentities("InvoiceAvoirAsk").' ';
- // $text.=' ';
- $text.='';
- if ($optionsav)
- {
- $text.=' ';
- $text.=$optionsav;
+ $text = $langs->transnoentities("InvoiceAvoirAsk") . ' ';
+ // $text.=' ';
+ $text .= 'trans("NoInvoiceToCorrect") . '';
}
- else
- {
- $text.=''.$langs->trans("NoInvoiceToCorrect").' ';
- }
- $text.=' ';
- $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1);
+ $text .= ' ';
+ $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1);
print $desc;
- print ' '."\n";
+ print '' . "\n";
}
-
+
print '
';
print ' ';
-
- if ($socid > 0)
- {
+
+ if ($socid > 0) {
// Discounts for third party
- print ''.$langs->trans('Discounts').' ';
- if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",'id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">'.$soc->remise_percent.' ');
- else print $langs->trans("CompanyHasNoRelativeDiscount");
- print ' id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">('.$langs->trans("EditRelativeDiscount").') ';
+ print ' ' . $langs->trans('Discounts') . ' ';
+ if ($soc->remise_percent)
+ print $langs->trans("CompanyHasRelativeDiscount", 'id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . $soc->remise_percent . ' ');
+ else
+ print $langs->trans("CompanyHasNoRelativeDiscount");
+ print ' id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditRelativeDiscount") . ') ';
print '. ';
print ' ';
- if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",'id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">'.price($absolute_discount).' ',$langs->trans("Currency".$conf->currency));
- else print $langs->trans("CompanyHasNoAbsoluteDiscount");
- print ' id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">('.$langs->trans("EditGlobalDiscounts").') ';
+ if ($absolute_discount)
+ print $langs->trans("CompanyHasAbsoluteDiscount", 'id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . price($absolute_discount) . ' ', $langs->trans("Currency" . $conf->currency));
+ else
+ print $langs->trans("CompanyHasNoAbsoluteDiscount");
+ print ' id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditGlobalDiscounts") . ') ';
print '.';
print ' ';
}
-
+
// Date invoice
- print ''.$langs->trans('Date').' ';
- $form->select_date($dateinvoice,'','','','',"add",1,1);
+ print ' ' . $langs->trans('Date') . ' ';
+ $form->select_date($dateinvoice, '', '', '', '', "add", 1, 1);
print ' ';
-
+
// Payment term
- print ''.$langs->trans('PaymentConditionsShort').' ';
- $form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
+ print ' ' . $langs->trans('PaymentConditionsShort') . ' ';
+ $form->select_conditions_paiements(isset($_POST ['cond_reglement_id']) ? $_POST ['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id');
print ' ';
-
+
// Payment mode
- print ''.$langs->trans('PaymentMode').' ';
- $form->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id');
+ print ' ' . $langs->trans('PaymentMode') . ' ';
+ $form->select_types_paiements(isset($_POST ['mode_reglement_id']) ? $_POST ['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id');
print ' ';
-
+
// Project
- if (! empty($conf->projet->enabled) && $socid>0)
- {
- $formproject=new FormProjets($db);
-
+ if (! empty($conf->projet->enabled) && $socid > 0) {
+ $formproject = new FormProjets($db);
+
$langs->load('projects');
- print ''.$langs->trans('Project').' ';
+ print ' ' . $langs->trans('Project') . ' ';
$formproject->select_projects($soc->id, $projectid, 'projectid');
print ' ';
}
-
+
// Other attributes
- $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook) && ! empty($extrafields->attribute_label))
- {
- print $object->showOptionals($extrafields,'edit');
+ $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"');
+ $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
+ // hook
+ if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+ print $object->showOptionals($extrafields, 'edit');
}
-
+
// Modele PDF
- print ''.$langs->trans('Model').' ';
+ print '' . $langs->trans('Model') . ' ';
print '';
- include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
- $liste=ModelePDFFactures::liste_modeles($db);
- print $form->selectarray('model',$liste,$conf->global->FACTURE_ADDON_PDF);
+ include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php';
+ $liste = ModelePDFFactures::liste_modeles($db);
+ print $form->selectarray('model', $liste, $conf->global->FACTURE_ADDON_PDF);
print " ";
-
+
// Public note
print '';
- print ''.$langs->trans('NotePublic').' ';
+ print '' . $langs->trans('NotePublic') . ' ';
print '';
- $note_public='';
- if (is_object($objectsrc)) // Take value from source object
+ $note_public = '';
+ if (is_object($objectsrc)) // Take value from source object
{
- $note_public=$objectsrc->note_public;
+ $note_public = $objectsrc->note_public;
}
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);
-
- //print ''.$note_public.' ';
-
+
+ // print ''.$note_public.' ';
+
// Private note
- if (empty($user->societe_id))
- {
+ if (empty($user->societe_id)) {
print '';
- print ''.$langs->trans('NotePrivate').' ';
+ print '' . $langs->trans('NotePrivate') . ' ';
print '';
- $note_private='';
- if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) // Take value from source object
+ $note_private = '';
+ if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) // Take value from source object
{
- $note_private=$objectsrc->note_private;
+ $note_private = $objectsrc->note_private;
}
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);
- //print ''.$note_private.'. ';
+ // print ''.$note_private.'. ';
}
-
- if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
- {
+
+ if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
// TODO for compatibility
- if ($origin == 'contrat')
- {
+ if ($origin == 'contrat') {
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
- $objectsrc->remise_absolue=$remise_absolue;
- $objectsrc->remise_percent=$remise_percent;
- $objectsrc->update_price(1,-1,1);
+ $objectsrc->remise_absolue = $remise_absolue;
+ $objectsrc->remise_percent = $remise_percent;
+ $objectsrc->update_price(1, - 1, 1);
}
-
- print "\n";
+
+ print "\n";
print "\n";
- print ' '."\n";
- print ' '."\n";
- print ' '."\n";
- print ' ';
- print ' ';
-
- $newclassname=$classname;
- if ($newclassname == 'Propal') $newclassname = 'CommercialProposal';
- elseif ($newclassname == 'Commande') $newclassname = 'Order';
- elseif ($newclassname == 'Expedition') $newclassname = 'Sending';
-
- print ''.$langs->trans($newclassname).' '.$objectsrc->getNomUrl(1).' ';
- print ''.$langs->trans('TotalHT').' '.price($objectsrc->total_ht).' ';
- print ''.$langs->trans('TotalVAT').' '.price($objectsrc->total_tva)." ";
- if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
+ print ' ' . "\n";
+ print ' ' . "\n";
+ print ' ' . "\n";
+ print ' ';
+ print ' ';
+
+ $newclassname = $classname;
+ if ($newclassname == 'Propal')
+ $newclassname = 'CommercialProposal';
+ elseif ($newclassname == 'Commande')
+ $newclassname = 'Order';
+ elseif ($newclassname == 'Expedition')
+ $newclassname = 'Sending';
+
+ print '' . $langs->trans($newclassname) . ' ' . $objectsrc->getNomUrl(1) . ' ';
+ print '' . $langs->trans('TotalHT') . ' ' . price($objectsrc->total_ht) . ' ';
+ print '' . $langs->trans('TotalVAT') . ' ' . price($objectsrc->total_tva) . " ";
+ if ($mysoc->localtax1_assuj == "1") // Localtax1 RE
{
- print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).' '.price($objectsrc->total_localtax1)." ";
+ print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . ' ' . price($objectsrc->total_localtax1) . " ";
}
-
- if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
+
+ if ($mysoc->localtax2_assuj == "1") // Localtax2 IRPF
{
- print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).' '.price($objectsrc->total_localtax2)." ";
+ print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ' ' . price($objectsrc->total_localtax2) . " ";
}
- print ''.$langs->trans('TotalTTC').' '.price($objectsrc->total_ttc)." ";
- }
- else
- {
+ print '' . $langs->trans('TotalTTC') . ' ' . price($objectsrc->total_ttc) . " ";
+ } else {
// Show deprecated optional form to add product line here
- if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE))
- {
+ if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) {
print '';
-
+
// Zone de choix des produits predefinis a la creation
print '';
print '';
- print ''.$langs->trans('ProductsAndServices').' ';
- print ''.$langs->trans('Qty').' ';
- print ''.$langs->trans('ReductionShort').' ';
+ print '' . $langs->trans('ProductsAndServices') . ' ';
+ print '' . $langs->trans('Qty') . ' ';
+ print '' . $langs->trans('ReductionShort') . ' ';
print ' ';
- if (! empty($conf->service->enabled))
- {
- print ''.$langs->trans('ServiceLimitedDuration').' ';
+ if (! empty($conf->service->enabled)) {
+ print '' . $langs->trans('ServiceLimitedDuration') . ' ';
}
print ' ';
- for ($i = 1 ; $i <= $NBLINES ; $i++)
- {
+ for($i = 1; $i <= $NBLINES; $i ++) {
print '';
print '';
// multiprix
if (! empty($conf->global->PRODUIT_MULTIPRICES))
- $form->select_produits('','idprod'.$i,'',$conf->product->limit_size,$soc->price_level);
+ $form->select_produits('', 'idprod' . $i, '', $conf->product->limit_size, $soc->price_level);
else
- $form->select_produits('','idprod'.$i,'',$conf->product->limit_size);
+ $form->select_produits('', 'idprod' . $i, '', $conf->product->limit_size);
print ' ';
- print ' ';
- print ' % ';
+ print ' ';
+ print ' % ';
print ' ';
// Si le module service est actif, on propose des dates de debut et fin a la ligne
- if (! empty($conf->service->enabled))
- {
+ if (! empty($conf->service->enabled)) {
print '';
print '';
print '';
- print $langs->trans('From').' ';
+ print $langs->trans('From') . ' ';
print ' ';
- print $form->select_date('','date_start'.$i,$usehm,$usehm,1,"add");
+ print $form->select_date('', 'date_start' . $i, $usehm, $usehm, 1, "add");
print ' ';
print '';
- print $langs->trans('to').' ';
+ print $langs->trans('to') . ' ';
print ' ';
- print $form->select_date('','date_end'.$i,$usehm,$usehm,1,"add");
+ print $form->select_date('', 'date_end' . $i, $usehm, $usehm, 1, "add");
print '
';
print ' ';
}
print " \n";
}
-
+
print '
';
print ' ';
}
}
-
+
print "
\n";
-
+
// Button "Create Draft"
- print ' ';
-
+ print ' ';
+
print "\n";
-
+
// Show origin lines
- if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
- {
+ if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
print ' ';
-
- $title=$langs->trans('ProductsAndServices');
+
+ $title = $langs->trans('ProductsAndServices');
print_titre($title);
-
+
print '';
-
+
$objectsrc->printOriginLinesList();
-
+
print '
';
}
-
+
print ' ';
-}
-else if ($id > 0 || ! empty($ref))
-{
+} else if ($id > 0 || ! empty($ref)) {
/*
* Show object in view mode
*/
-
- $result=$object->fetch($id,$ref);
- if ($result <= 0) { dol_print_error($db, $object->error); exit; }
-
+
+ $result = $object->fetch($id, $ref);
+ if ($result <= 0) {
+ dol_print_error($db, $object->error);
+ exit();
+ }
+
// fetch optionals attributes and labels
- $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
-
- if ($user->societe_id>0 && $user->societe_id!=$object->socid) accessforbidden('',0);
-
- $result=$object->fetch_thirdparty();
-
+ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+
+ if ($user->societe_id > 0 && $user->societe_id != $object->socid)
+ accessforbidden('', 0);
+
+ $result = $object->fetch_thirdparty();
+
$soc = new Societe($db);
$soc->fetch($object->socid);
- $selleruserevenustamp=$mysoc->useRevenueStamp();
-
- $totalpaye = $object->getSommePaiement();
+ $selleruserevenustamp = $mysoc->useRevenueStamp();
+
+ $totalpaye = $object->getSommePaiement();
$totalcreditnotes = $object->getSumCreditNotesUsed();
$totaldeposits = $object->getSumDepositsUsed();
- //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits." selleruserrevenuestamp=".$selleruserevenustamp;
-
+ // print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits."
+ // selleruserrevenuestamp=".$selleruserevenustamp;
+
// We can also use bcadd to avoid pb with floating points
// For example print 239.2 - 229.3 - 9.9; does not return 0.
- //$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
- //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
- $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
-
- if ($object->paye) $resteapayer=0;
- $resteapayeraffiche=$resteapayer;
-
- if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
- {
- $filterabsolutediscount="fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
- $filtercreditnote="fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
+ // $resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
+ // $resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
+ $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
+
+ if ($object->paye)
+ $resteapayer = 0;
+ $resteapayeraffiche = $resteapayer;
+
+ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
+ $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
+ $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
+ } else {
+ $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
+ $filtercreditnote = "fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
}
- else
- {
- $filterabsolutediscount="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
- $filtercreditnote="fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
- }
-
- $absolute_discount=$soc->getAvailableDiscounts('',$filterabsolutediscount);
- $absolute_creditnote=$soc->getAvailableDiscounts('',$filtercreditnote);
- $absolute_discount=price2num($absolute_discount,'MT');
- $absolute_creditnote=price2num($absolute_creditnote,'MT');
-
+
+ $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
+ $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
+ $absolute_discount = price2num($absolute_discount, 'MT');
+ $absolute_creditnote = price2num($absolute_creditnote, 'MT');
+
$author = new User($db);
- if ($object->user_author)
- {
+ if ($object->user_author) {
$author->fetch($object->user_author);
}
-
- $objectidnext=$object->getIdReplacingInvoice();
-
+
+ $objectidnext = $object->getIdReplacingInvoice();
+
$head = facture_prepare_head($object);
-
+
dol_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer'), 0, 'bill');
-
- $formconfirm='';
-
+
+ $formconfirm = '';
+
// Confirmation de la conversion de l'avoir en reduc
- if ($action == 'converttoreduc')
- {
- $text=$langs->trans('ConfirmConvertToReduc');
- $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('ConvertToReduc'),$text,'confirm_converttoreduc','',"yes",2);
+ if ($action == 'converttoreduc') {
+ $text = $langs->trans('ConfirmConvertToReduc');
+ $formconfirm = $form->formconfirm($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2);
}
-
+
// Confirmation to delete invoice
- if ($action == 'delete')
- {
- $text=$langs->trans('ConfirmDeleteBill',$object->ref);
- $formquestion=array();
-
- $qualified_for_stock_change=0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(2);
+ if ($action == 'delete') {
+ $text = $langs->trans('ConfirmDeleteBill', $object->ref);
+ $formquestion = array();
+
+ $qualified_for_stock_change = 0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
+ $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ } else {
+ $qualified_for_stock_change = $object->hasProductsOrServices(1);
}
- else
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(1);
- }
-
- if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change && $object->statut>=1)
- {
+
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change && $object->statut >= 1) {
$langs->load("stocks");
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- $formproduct=new FormProduct($db);
- $label=$object->type==2?$langs->trans("SelectWarehouseForStockDecrease"):$langs->trans("SelectWarehouseForStockIncrease");
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1,0,0,$langs->trans("NoStockAction"))));
- $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('DeleteBill'),$text,'confirm_delete',$formquestion,"yes",1);
- }else {
- $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('DeleteBill'),$text,'confirm_delete','','',1);
+ require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
+ $formproduct = new FormProduct($db);
+ $label = $object->type == 2 ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease");
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
+ // 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
+ // => 1),
+ array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1, 0, 0, $langs->trans("NoStockAction"))));
+ $formconfirm = $form->formconfirm($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', $formquestion, "yes", 1);
+ } else {
+ $formconfirm = $form->formconfirm($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', '', '', 1);
}
}
-
+
// Confirmation de la validation
- if ($action == 'valid')
- {
+ if ($action == 'valid') {
// on verifie si l'objet est en numerotation provisoire
$objectref = substr($object->ref, 1, 4);
- if ($objectref == 'PROV')
- {
- $savdate=$object->date;
- if (! empty($conf->global->FAC_FORCE_DATE_VALIDATION))
- {
- $object->date=dol_now();
- $object->date_lim_reglement=$object->calculate_date_lim_reglement();
+ if ($objectref == 'PROV') {
+ $savdate = $object->date;
+ if (! empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
+ $object->date = dol_now();
+ $object->date_lim_reglement = $object->calculate_date_lim_reglement();
}
$numref = $object->getNextNumRef($soc);
- //$object->date=$savdate;
- }
- else
- {
+ // $object->date=$savdate;
+ } else {
$numref = $object->ref;
}
-
- $text=$langs->trans('ConfirmValidateBill',$numref);
- if (! empty($conf->notification->enabled))
- {
- require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
- $notify=new Notify($db);
- $text.=' ';
- $text.=$notify->confirmMessage('BILL_VALIDATE',$object->socid);
+
+ $text = $langs->trans('ConfirmValidateBill', $numref);
+ if (! empty($conf->notification->enabled)) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
+ $notify = new Notify($db);
+ $text .= ' ';
+ $text .= $notify->confirmMessage('BILL_VALIDATE', $object->socid);
}
- $formquestion=array();
-
- $qualified_for_stock_change=0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(2);
+ $formquestion = array();
+
+ $qualified_for_stock_change = 0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
+ $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ } else {
+ $qualified_for_stock_change = $object->hasProductsOrServices(1);
}
- else
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(1);
- }
-
- if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
- {
+
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
$langs->load("stocks");
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
- $formproduct=new FormProduct($db);
+ require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
+ require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
+ $formproduct = new FormProduct($db);
$warehouse = new Entrepot($db);
$warehouse_array = $warehouse->list_array();
if (count($warehouse_array) == 1) {
- $label = $object->type==2?$langs->trans("WarehouseForStockIncrease", current($warehouse_array)):$langs->trans("WarehouseForStockDecrease", current($warehouse_array));
+ $label = $object->type == 2 ? $langs->trans("WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans("WarehouseForStockDecrease", current($warehouse_array));
$value = ' ';
} else {
- $label = $object->type==2?$langs->trans("SelectWarehouseForStockIncrease"):$langs->trans("SelectWarehouseForStockDecrease");
- $value = $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1);
+ $label = $object->type == 2 ? $langs->trans("SelectWarehouseForStockIncrease") : $langs->trans("SelectWarehouseForStockDecrease");
+ $value = $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1);
}
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value));
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
+ // 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
+ // => 1),
+ array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value));
}
- if ($object->type != 2 && $object->total_ttc < 0) // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on
+ if ($object->type != 2 && $object->total_ttc < 0) // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on
{
- $text.=' '.img_warning().' '.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive");
+ $text .= ' ' . img_warning() . ' ' . $langs->trans("ErrorInvoiceOfThisTypeMustBePositive");
}
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ValidateBill'),$text,'confirm_valid',$formquestion,(($object->type != 2 && $object->total_ttc < 0)?"no":"yes"),($conf->notification->enabled?0:2));
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, (($object->type != 2 && $object->total_ttc < 0) ? "no" : "yes"), ($conf->notification->enabled ? 0 : 2));
}
-
+
// Confirm back to draft status
- if ($action == 'modif')
- {
- $text=$langs->trans('ConfirmUnvalidateBill',$object->ref);
- $formquestion=array();
-
- $qualified_for_stock_change=0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(2);
+ if ($action == 'modif') {
+ $text = $langs->trans('ConfirmUnvalidateBill', $object->ref);
+ $formquestion = array();
+
+ $qualified_for_stock_change = 0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
+ $qualified_for_stock_change = $object->hasProductsOrServices(2);
+ } else {
+ $qualified_for_stock_change = $object->hasProductsOrServices(1);
}
- else
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(1);
- }
- if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
- {
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
$langs->load("stocks");
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
- $formproduct=new FormProduct($db);
+ require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
+ require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
+ $formproduct = new FormProduct($db);
$warehouse = new Entrepot($db);
$warehouse_array = $warehouse->list_array();
if (count($warehouse_array) == 1) {
- $label = $object->type==2?$langs->trans("WarehouseForStockDecrease", current($warehouse_array)):$langs->trans("WarehouseForStockIncrease", current($warehouse_array));
+ $label = $object->type == 2 ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array));
$value = ' ';
} else {
- $label=$object->type==2?$langs->trans("SelectWarehouseForStockDecrease"):$langs->trans("SelectWarehouseForStockIncrease");
- $value = $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1);
+ $label = $object->type == 2 ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease");
+ $value = $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1);
}
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
- //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
- array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value));
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
+ // 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
+ // => 1),
+ array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value));
}
-
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('UnvalidateBill'),$text,'confirm_modif',$formquestion,"yes",1);
+
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('UnvalidateBill'), $text, 'confirm_modif', $formquestion, "yes", 1);
}
-
+
// Confirmation du classement paye
- if ($action == 'paid' && $resteapayer <= 0)
- {
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ClassifyPaid'),$langs->trans('ConfirmClassifyPaidBill',$object->ref),'confirm_paid','',"yes",1);
+ if ($action == 'paid' && $resteapayer <= 0) {
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', "yes", 1);
}
- if ($action == 'paid' && $resteapayer > 0)
- {
+ if ($action == 'paid' && $resteapayer > 0) {
// Code
- $i=0;
- $close[$i]['code']='discount_vat';$i++;
- $close[$i]['code']='badcustomer';$i++;
+ $i = 0;
+ $close [$i] ['code'] = 'discount_vat';
+ $i ++;
+ $close [$i] ['code'] = 'badcustomer';
+ $i ++;
// Help
- $i=0;
- $close[$i]['label']=$langs->trans("HelpEscompte").' '.$langs->trans("ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");$i++;
- $close[$i]['label']=$langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");$i++;
+ $i = 0;
+ $close [$i] ['label'] = $langs->trans("HelpEscompte") . ' ' . $langs->trans("ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
+ $i ++;
+ $close [$i] ['label'] = $langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
+ $i ++;
// Texte
- $i=0;
- $close[$i]['reason']=$form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonDiscountVat",$resteapayer,$langs->trans("Currency".$conf->currency)),$close[$i]['label'],1);$i++;
- $close[$i]['reason']=$form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer",$resteapayer,$langs->trans("Currency".$conf->currency)),$close[$i]['label'],1);$i++;
+ $i = 0;
+ $close [$i] ['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonDiscountVat", $resteapayer, $langs->trans("Currency" . $conf->currency)), $close [$i] ['label'], 1);
+ $i ++;
+ $close [$i] ['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans("Currency" . $conf->currency)), $close [$i] ['label'], 1);
+ $i ++;
// arrayreasons[code]=reason
- foreach($close as $key => $val)
- {
- $arrayreasons[$close[$key]['code']]=$close[$key]['reason'];
+ foreach ($close as $key => $val) {
+ $arrayreasons [$close [$key] ['code']] = $close [$key] ['reason'];
}
-
+
// Cree un tableau formulaire
- $formquestion=array(
- 'text' => $langs->trans("ConfirmClassifyPaidPartiallyQuestion"),
- array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons),
- array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100')
- );
+ $formquestion = array('text' => $langs->trans("ConfirmClassifyPaidPartiallyQuestion"),array('type' => 'radio','name' => 'close_code','label' => $langs->trans("Reason"),'values' => $arrayreasons),array('type' => 'text','name' => 'close_note','label' => $langs->trans("Comment"),'value' => '','size' => '100'));
// Paiement incomplet. On demande si motif = escompte ou autre
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ClassifyPaid'),$langs->trans('ConfirmClassifyPaidPartially',$object->ref),'confirm_paid_partially',$formquestion,"yes");
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidPartially', $object->ref), 'confirm_paid_partially', $formquestion, "yes");
}
-
+
// Confirmation du classement abandonne
- if ($action == 'canceled')
- {
+ if ($action == 'canceled') {
// S'il y a une facture de remplacement pas encore validee (etat brouillon),
// on ne permet pas de classer abandonner la facture.
- if ($objectidnext)
- {
- $facturereplacement=new Facture($db);
+ if ($objectidnext) {
+ $facturereplacement = new Facture($db);
$facturereplacement->fetch($objectidnext);
- $statusreplacement=$facturereplacement->statut;
+ $statusreplacement = $facturereplacement->statut;
}
- if ($objectidnext && $statusreplacement == 0)
- {
- print ''.$langs->trans("ErrorCantCancelIfReplacementInvoiceNotValidated").'
';
- }
- else
- {
+ if ($objectidnext && $statusreplacement == 0) {
+ print '' . $langs->trans("ErrorCantCancelIfReplacementInvoiceNotValidated") . '
';
+ } else {
// Code
- $close[1]['code']='badcustomer';
- $close[2]['code']='abandon';
+ $close [1] ['code'] = 'badcustomer';
+ $close [2] ['code'] = 'abandon';
// Help
- $close[1]['label']=$langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
- $close[2]['label']=$langs->trans("ConfirmClassifyAbandonReasonOtherDesc");
+ $close [1] ['label'] = $langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
+ $close [2] ['label'] = $langs->trans("ConfirmClassifyAbandonReasonOtherDesc");
// Texte
- $close[1]['reason']=$form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer",$object->ref),$close[1]['label'],1);
- $close[2]['reason']=$form->textwithpicto($langs->transnoentities("ConfirmClassifyAbandonReasonOther"),$close[2]['label'],1);
+ $close [1] ['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer", $object->ref), $close [1] ['label'], 1);
+ $close [2] ['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyAbandonReasonOther"), $close [2] ['label'], 1);
// arrayreasons
- $arrayreasons[$close[1]['code']]=$close[1]['reason'];
- $arrayreasons[$close[2]['code']]=$close[2]['reason'];
-
+ $arrayreasons [$close [1] ['code']] = $close [1] ['reason'];
+ $arrayreasons [$close [2] ['code']] = $close [2] ['reason'];
+
// Cree un tableau formulaire
- $formquestion=array(
- 'text' => $langs->trans("ConfirmCancelBillQuestion"),
- array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons),
- array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100')
- );
-
- $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('CancelBill'),$langs->trans('ConfirmCancelBill',$object->ref),'confirm_canceled',$formquestion,"yes");
+ $formquestion = array('text' => $langs->trans("ConfirmCancelBillQuestion"),array('type' => 'radio','name' => 'close_code','label' => $langs->trans("Reason"),'values' => $arrayreasons),array('type' => 'text','name' => 'close_note','label' => $langs->trans("Comment"),'value' => '','size' => '100'));
+
+ $formconfirm = $form->formconfirm($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('CancelBill'), $langs->trans('ConfirmCancelBill', $object->ref), 'confirm_canceled', $formquestion, "yes");
}
}
-
+
// Confirmation de la suppression d'une ligne produit
- if ($action == 'ask_deleteline')
- {
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
+ if ($action == 'ask_deleteline') {
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
}
-
+
// Clone confirmation
- if ($action == 'clone')
- {
+ if ($action == 'clone') {
// Create an array for form
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
- array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company('','socid','(s.client=1 OR s.client=2 OR s.client=3)',1))
- );
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
+ array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company('', 'socid', '(s.client=1 OR s.client=2 OR s.client=3)', 1)));
// Paiement incomplet. On demande si motif = escompte ou autre
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes',1);
+ $formconfirm = $form->formconfirm($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('CloneInvoice'), $langs->trans('ConfirmCloneInvoice', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
}
-
- if (! $formconfirm)
- {
- $parameters=array('lineid'=>$lineid);
- $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+
+ if (! $formconfirm) {
+ $parameters = array('lineid' => $lineid);
+ $formconfirm = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by
+ // hook
}
-
+
// Print form confirm
print $formconfirm;
-
-
-
-
+
// Invoice content
-
+
print '';
-
- $linkback = ''.$langs->trans("BackToList").' ';
-
+
+ $linkback = '' . $langs->trans("BackToList") . ' ';
+
// Ref
- print ''.$langs->trans('Ref').' ';
+ print '' . $langs->trans('Ref') . ' ';
print '';
- $morehtmlref='';
- $discount=new DiscountAbsolute($db);
- $result=$discount->fetch(0,$object->id);
- if ($result > 0)
- {
- $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
+ $morehtmlref = '';
+ $discount = new DiscountAbsolute($db);
+ $result = $discount->fetch(0, $object->id);
+ if ($result > 0) {
+ $morehtmlref = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", $discount->getNomUrl(1, 'discount')) . ')';
}
- if ($result < 0)
- {
- dol_print_error('',$discount->error);
+ if ($result < 0) {
+ dol_print_error('', $discount->error);
}
print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
print ' ';
-
+
// Ref customer
print '';
print '';
print ' ';
print '';
- if ($user->rights->facture->creer && $action == 'refclient')
- {
- print 'id.'" method="post">';
- print ' ';
+ if ($user->rights->facture->creer && $action == 'refclient') {
+ print ' id . '" method="post">';
+ print ' ';
print ' ';
- print ' ';
- print ' ';
+ print ' ';
+ print ' ';
print ' ';
- }
- else
- {
+ } else {
print $object->ref_client;
}
print ' ';
-
+
// Third party
print '';
print '';
print ' ';
- if ($action == 'editthirdparty')
- {
- $form->form_thirdparty($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->socid,'socid');
- }
- else
- {
- print ' '.$soc->getNomUrl(1,'compta');
+ if ($action == 'editthirdparty') {
+ $form->form_thirdparty($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->socid, 'socid');
+ } else {
+ print ' ' . $soc->getNomUrl(1, 'compta');
print ' ';
- print '('.$langs->trans('OtherBills').' ';
+ print '(' . $langs->trans('OtherBills') . ' ';
// Outstanding Bill
- $outstandigBills=$soc->get_OutstandingBill();
- print ' - '.$langs->trans('CurrentOutstandingBill').': ';
- print price($outstandigBills,'',$langs,0,0,-1,$conf->currency);
- if ($soc->outstanding_limit != '')
- {
- if ($outstandigBills > $soc->outstanding_limit) print img_warning($langs->trans("OutstandingBillReached"));
- print ' / '.price($soc->outstanding_limit);
+ $outstandigBills = $soc->get_OutstandingBill();
+ print ' - ' . $langs->trans('CurrentOutstandingBill') . ': ';
+ print price($outstandigBills, '', $langs, 0, 0, - 1, $conf->currency);
+ if ($soc->outstanding_limit != '') {
+ if ($outstandigBills > $soc->outstanding_limit)
+ print img_warning($langs->trans("OutstandingBillReached"));
+ print ' / ' . price($soc->outstanding_limit);
}
print ')';
}
print ' ';
-
+
// Type
- print ''.$langs->trans('Type').' ';
+ print ' ' . $langs->trans('Type') . ' ';
print $object->getLibType();
- if ($object->type == 1)
- {
- $facreplaced=new Facture($db);
+ if ($object->type == 1) {
+ $facreplaced = new Facture($db);
$facreplaced->fetch($object->fk_facture_source);
- print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
+ print ' (' . $langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)) . ')';
}
- if ($object->type == 2)
- {
- $facusing=new Facture($db);
+ if ($object->type == 2) {
+ $facusing = new Facture($db);
$facusing->fetch($object->fk_facture_source);
- print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
+ print ' (' . $langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)) . ')';
}
-
- $facidavoir=$object->getListIdAvoirFromInvoice();
- if (count($facidavoir) > 0)
- {
- print ' ('.$langs->transnoentities("InvoiceHasAvoir");
- $i=0;
- foreach($facidavoir as $id)
- {
- if ($i==0) print ' ';
- else print ',';
- $facavoir=new Facture($db);
+
+ $facidavoir = $object->getListIdAvoirFromInvoice();
+ if (count($facidavoir) > 0) {
+ print ' (' . $langs->transnoentities("InvoiceHasAvoir");
+ $i = 0;
+ foreach ($facidavoir as $id) {
+ if ($i == 0)
+ print ' ';
+ else
+ print ',';
+ $facavoir = new Facture($db);
$facavoir->fetch($id);
print $facavoir->getNomUrl(1);
}
print ')';
}
- if ($objectidnext > 0)
- {
- $facthatreplace=new Facture($db);
+ if ($objectidnext > 0) {
+ $facthatreplace = new Facture($db);
$facthatreplace->fetch($objectidnext);
- print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
+ print ' (' . $langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)) . ')';
}
print ' ';
-
+
// Relative and absolute discounts
- $addrelativediscount='id.'">'.$langs->trans("EditRelativeDiscounts").' ';
- $addabsolutediscount='id.'">'.$langs->trans("EditGlobalDiscounts").' ';
- $addcreditnote='id.'">'.$langs->trans("AddCreditNote").' ';
-
- print ''.$langs->trans('Discounts');
+ $addrelativediscount = 'id . '">' . $langs->trans("EditRelativeDiscounts") . ' ';
+ $addabsolutediscount = 'id . '">' . $langs->trans("EditGlobalDiscounts") . ' ';
+ $addcreditnote = 'id . '">' . $langs->trans("AddCreditNote") . ' ';
+
+ print ' ' . $langs->trans('Discounts');
print ' ';
- if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_percent);
- else print $langs->trans("CompanyHasNoRelativeDiscount");
- //print ' ('.$addrelativediscount.')';
-
- if ($absolute_discount > 0)
- {
+ if ($soc->remise_percent)
+ print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
+ else
+ print $langs->trans("CompanyHasNoRelativeDiscount");
+ // print ' ('.$addrelativediscount.')';
+
+ if ($absolute_discount > 0) {
print '. ';
- if ($object->statut > 0 || $object->type == 2 || $object->type == 3)
- {
- if ($object->statut == 0)
- {
- print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
+ if ($object->statut > 0 || $object->type == 2 || $object->type == 3) {
+ if ($object->statut == 0) {
+ print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
print '. ';
- }
- else
- {
- if ($object->statut < 1 || $object->type == 2 || $object->type == 3)
- {
- $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
- print ' '.$text.'. ';
- }
- else
- {
- $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
- $text2=$langs->trans("AbsoluteDiscountUse");
- print $form->textwithpicto($text,$text2);
+ } else {
+ if ($object->statut < 1 || $object->type == 2 || $object->type == 3) {
+ $text = $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
+ print ' ' . $text . '. ';
+ } else {
+ $text = $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
+ $text2 = $langs->trans("AbsoluteDiscountUse");
+ print $form->textwithpicto($text, $text2);
}
}
- }
- else
- {
+ } else {
// Remise dispo de type remise fixe (not credit note)
print ' ';
- $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, $resteapayer, ' ('.$addabsolutediscount.')');
+ $form->form_remise_dispo($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, $resteapayer, ' (' . $addabsolutediscount . ')');
}
- }
- else
- {
- if ($absolute_creditnote > 0) // If not, link will be added later
+ } else {
+ if ($absolute_creditnote > 0) // If not, link will be added later
{
- if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' ('.$addabsolutediscount.') ';
- else print '. ';
- }
- else print '. ';
- }
- if ($absolute_creditnote > 0)
- {
- // If validated, we show link "add credit note to payment"
- if ($object->statut != 1 || $object->type == 2 || $object->type == 3)
- {
- if ($object->statut == 0 && $object->type != 3)
- {
- $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency));
- print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse"));
- }
+ if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
+ print ' (' . $addabsolutediscount . ') ';
else
- {
- print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'.';
+ print '. ';
+ } else
+ print '. ';
+ }
+ if ($absolute_creditnote > 0) {
+ // If validated, we show link "add credit note to payment"
+ if ($object->statut != 1 || $object->type == 2 || $object->type == 3) {
+ if ($object->statut == 0 && $object->type != 3) {
+ $text = $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency));
+ print $form->textwithpicto($text, $langs->trans("CreditNoteDepositUse"));
+ } else {
+ print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '.';
}
- }
- else
- {
+ } else {
// Remise dispo de type avoir
- if (! $absolute_discount) print ' ';
- //$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer);
- $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0); // We must allow credit not even if amount is higher
+ if (! $absolute_discount)
+ print ' ';
+ // $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote,
+ // $filtercreditnote, $resteapayer);
+ $form->form_remise_dispo($_SERVER ["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0); // We
+ // must
+ // allow
+ // credit
+ // not
+ // even
+ // if
+ // amount
+ // is
+ // higher
}
}
- if (! $absolute_discount && ! $absolute_creditnote)
- {
+ if (! $absolute_discount && ! $absolute_creditnote) {
print $langs->trans("CompanyHasNoAbsoluteDiscount");
- if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' ('.$addabsolutediscount.') ';
- else print '. ';
+ if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
+ print ' (' . $addabsolutediscount . ') ';
+ else
+ print '. ';
}
- //if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
+ // if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
// {
- //if (! $absolute_discount && ! $absolute_creditnote) print ' ';
- //print ' - ';
- //print $addabsolutediscount;
- //print ' - '.$addcreditnote; // We disbale link to credit note
- //}
+ // if (! $absolute_discount && ! $absolute_creditnote) print ' ';
+ // print ' - ';
+ // print $addabsolutediscount;
+ // print ' - '.$addcreditnote; // We disbale link to credit note
+ // }
print ' ';
-
+
// Date invoice
print '';
print '';
print ' ';
-
- if ($object->type != 2)
- {
- if ($action == 'editinvoicedate')
- {
- $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date,'invoicedate');
+
+ if ($object->type != 2) {
+ if ($action == 'editinvoicedate') {
+ $form->form_date($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->date, 'invoicedate');
+ } else {
+ print dol_print_date($object->date, 'daytext');
}
- else
- {
- print dol_print_date($object->date,'daytext');
- }
- }
- else
- {
- print dol_print_date($object->date,'daytext');
+ } else {
+ print dol_print_date($object->date, 'daytext');
}
print ' ';
-
-
+
// List of payments
-
- $sign=1;
- if ($object->type == 2) $sign=-1;
-
- $nbrows=8; $nbcols=2;
- if (! empty($conf->projet->enabled)) $nbrows++;
- if (! empty($conf->banque->enabled)) $nbcols++;
- //if (! empty($soc->outstandingbill)) $nbrows++;
- if($mysoc->localtax1_assuj=="1") $nbrows++;
- if($mysoc->localtax2_assuj=="1") $nbrows++;
- if ($selleruserevenustamp) $nbrows++;
-
- print '';
-
+
+ $sign = 1;
+ if ($object->type == 2)
+ $sign = - 1;
+
+ $nbrows = 8;
+ $nbcols = 2;
+ if (! empty($conf->projet->enabled))
+ $nbrows ++;
+ if (! empty($conf->banque->enabled))
+ $nbcols ++;
+ // if (! empty($soc->outstandingbill)) $nbrows++;
+ if ($mysoc->localtax1_assuj == "1")
+ $nbrows ++;
+ if ($mysoc->localtax2_assuj == "1")
+ $nbrows ++;
+ if ($selleruserevenustamp)
+ $nbrows ++;
+
+ print ' ';
+
print '';
-
+
// List of payments already done
print '';
- print ''.($object->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).' ';
- print ''.$langs->trans('Type').' ';
- if (! empty($conf->banque->enabled)) print ''.$langs->trans('BankAccount').' ';
- print ''.$langs->trans('Amount').' ';
+ print '' . ($object->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . ' ';
+ print '' . $langs->trans('Type') . ' ';
+ if (! empty($conf->banque->enabled))
+ print '' . $langs->trans('BankAccount') . ' ';
+ print '' . $langs->trans('Amount') . ' ';
print ' ';
print ' ';
-
- $var=true;
-
+
+ $var = true;
+
// Payments already done (from payment on this invoice)
$sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,';
- $sql.= ' c.code as payment_code, c.libelle as payment_label,';
- $sql.= ' pf.amount,';
- $sql.= ' ba.rowid as baid, ba.ref, ba.label';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'paiement as p';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
- $sql.= ' WHERE pf.fk_facture = '.$object->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
- $sql.= ' ORDER BY p.datep, p.tms';
-
+ $sql .= ' c.code as payment_code, c.libelle as payment_label,';
+ $sql .= ' pf.amount,';
+ $sql .= ' ba.rowid as baid, ba.ref, ba.label';
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p';
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
+ $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
+ $sql .= ' ORDER BY p.datep, p.tms';
+
$result = $db->query($sql);
- if ($result)
- {
+ if ($result) {
$num = $db->num_rows($result);
$i = 0;
-
- //if ($object->type != 2)
- //{
- if ($num > 0)
- {
- while ($i < $num)
- {
+
+ // if ($object->type != 2)
+ // {
+ if ($num > 0) {
+ while ($i < $num) {
$objp = $db->fetch_object($result);
- $var=!$var;
- print '';
- print ''.img_object($langs->trans('ShowPayment'),'payment').' ';
- print dol_print_date($db->jdate($objp->dp),'day').' ';
- $label=($langs->trans("PaymentType".$objp->payment_code)!=("PaymentType".$objp->payment_code))?$langs->trans("PaymentType".$objp->payment_code):$objp->payment_label;
- print ''.$label.' '.$objp->num_paiement.' ';
- if (! empty($conf->banque->enabled))
- {
- $bankaccountstatic->id=$objp->baid;
- $bankaccountstatic->ref=$objp->ref;
- $bankaccountstatic->label=$objp->ref;
+ $var = ! $var;
+ print '';
+ print '' . img_object($langs->trans('ShowPayment'), 'payment') . ' ';
+ print dol_print_date($db->jdate($objp->dp), 'day') . ' ';
+ $label = ($langs->trans("PaymentType" . $objp->payment_code) != ("PaymentType" . $objp->payment_code)) ? $langs->trans("PaymentType" . $objp->payment_code) : $objp->payment_label;
+ print '' . $label . ' ' . $objp->num_paiement . ' ';
+ if (! empty($conf->banque->enabled)) {
+ $bankaccountstatic->id = $objp->baid;
+ $bankaccountstatic->ref = $objp->ref;
+ $bankaccountstatic->label = $objp->ref;
print '';
- if ($bankaccountstatic->id) print $bankaccountstatic->getNomUrl(1,'transactions');
+ if ($bankaccountstatic->id)
+ print $bankaccountstatic->getNomUrl(1, 'transactions');
print ' ';
}
- print ''.price($sign * $objp->amount).' ';
+ print '' . price($sign * $objp->amount) . ' ';
print ' ';
print ' ';
- $i++;
+ $i ++;
}
+ } else {
+ print '' . $langs->trans("None") . ' ';
}
- else
- {
- print ''.$langs->trans("None").' ';
- }
- //}
+ // }
$db->free($result);
- }
- else
- {
+ } else {
dol_print_error($db);
}
-
- if ($object->type != 2)
- {
+
+ if ($object->type != 2) {
// Total already paid
- print '';
- if ($object->type != 3) print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits');
- else print $langs->trans('AlreadyPaid');
- print ' : '.price($totalpaye).' ';
-
- $resteapayeraffiche=$resteapayer;
-
+ print '';
+ if ($object->type != 3)
+ print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits');
+ else
+ print $langs->trans('AlreadyPaid');
+ print ' : ' . price($totalpaye) . ' ';
+
+ $resteapayeraffiche = $resteapayer;
+
// Loop on each credit note or deposit amount applied
- $creditnoteamount=0;
- $depositamount=0;
+ $creditnoteamount = 0;
+ $depositamount = 0;
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
- $sql.= " re.description, re.fk_facture_source";
- $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
- $sql.= " WHERE fk_facture = ".$object->id;
- $resql=$db->query($sql);
- if ($resql)
- {
+ $sql .= " re.description, re.fk_facture_source";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re";
+ $sql .= " WHERE fk_facture = " . $object->id;
+ $resql = $db->query($sql);
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- $invoice=new Facture($db);
- while ($i < $num)
- {
+ $invoice = new Facture($db);
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$invoice->fetch($obj->fk_facture_source);
- print '';
- if ($invoice->type == 2) print $langs->trans("CreditNote").' ';
- if ($invoice->type == 3) print $langs->trans("Deposit").' ';
+ print ' ';
+ if ($invoice->type == 2)
+ print $langs->trans("CreditNote") . ' ';
+ if ($invoice->type == 3)
+ print $langs->trans("Deposit") . ' ';
print $invoice->getNomUrl(0);
print ' : ';
- print ''.price($obj->amount_ttc).' ';
+ print '' . price($obj->amount_ttc) . ' ';
print '';
- print 'id.'&action=unlinkdiscount&discountid='.$obj->rowid.'">'.img_delete().' ';
+ print 'id . '&action=unlinkdiscount&discountid=' . $obj->rowid . '">' . img_delete() . ' ';
print ' ';
- $i++;
- if ($invoice->type == 2) $creditnoteamount += $obj->amount_ttc;
- if ($invoice->type == 3) $depositamount += $obj->amount_ttc;
+ $i ++;
+ if ($invoice->type == 2)
+ $creditnoteamount += $obj->amount_ttc;
+ if ($invoice->type == 3)
+ $depositamount += $obj->amount_ttc;
}
- }
- else
- {
+ } else {
dol_print_error($db);
}
-
+
// Paye partiellement 'escompte'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'discount_vat')
- {
- print '';
- print $form->textwithpicto($langs->trans("Discount").':',$langs->trans("HelpEscompte"),-1);
- print ' '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' ';
- $resteapayeraffiche=0;
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'discount_vat') {
+ print '';
+ print $form->textwithpicto($langs->trans("Discount") . ':', $langs->trans("HelpEscompte"), - 1);
+ print ' ' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' ';
+ $resteapayeraffiche = 0;
}
// Paye partiellement ou Abandon 'badcustomer'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'badcustomer')
- {
- print '';
- print $form->textwithpicto($langs->trans("Abandoned").':',$langs->trans("HelpAbandonBadCustomer"),-1);
- print ' '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' ';
- //$resteapayeraffiche=0;
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'badcustomer') {
+ print '';
+ print $form->textwithpicto($langs->trans("Abandoned") . ':', $langs->trans("HelpAbandonBadCustomer"), - 1);
+ print ' ' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' ';
+ // $resteapayeraffiche=0;
}
// Paye partiellement ou Abandon 'product_returned'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'product_returned')
- {
- print '';
- print $form->textwithpicto($langs->trans("ProductReturned").':',$langs->trans("HelpAbandonProductReturned"),-1);
- print ' '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' ';
- $resteapayeraffiche=0;
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'product_returned') {
+ print '';
+ print $form->textwithpicto($langs->trans("ProductReturned") . ':', $langs->trans("HelpAbandonProductReturned"), - 1);
+ print ' ' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' ';
+ $resteapayeraffiche = 0;
}
// Paye partiellement ou Abandon 'abandon'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'abandon')
- {
- print '';
- $text=$langs->trans("HelpAbandonOther");
- if ($object->close_note) $text.=''.$langs->trans("Reason").' :'.$object->close_note;
- print $form->textwithpicto($langs->trans("Abandoned").':',$text,-1);
- print ' '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' ';
- $resteapayeraffiche=0;
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'abandon') {
+ print '';
+ $text = $langs->trans("HelpAbandonOther");
+ if ($object->close_note)
+ $text .= '' . $langs->trans("Reason") . ' :' . $object->close_note;
+ print $form->textwithpicto($langs->trans("Abandoned") . ':', $text, - 1);
+ print ' ' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' ';
+ $resteapayeraffiche = 0;
}
-
+
// Billed
- print ''.$langs->trans("Billed").' : '.price($object->total_ttc).' ';
-
+ print '' . $langs->trans("Billed") . ' : ' . price($object->total_ttc) . ' ';
+
// Remainder to pay
- print '';
- if ($resteapayeraffiche >= 0) print $langs->trans('RemainderToPay');
- else print $langs->trans('ExcessReceived');
+ print ' ';
+ if ($resteapayeraffiche >= 0)
+ print $langs->trans('RemainderToPay');
+ else
+ print $langs->trans('ExcessReceived');
print ' : ';
- print ''.price($resteapayeraffiche).' ';
+ print '' . price($resteapayeraffiche) . ' ';
print ' ';
- }
- else // Credit note
+ } else // Credit note
{
// Total already paid back
- print '';
+ print ' ';
print $langs->trans('AlreadyPaidBack');
- print ' : '.price($sign * $totalpaye).' ';
-
+ print ' :' . price($sign * $totalpaye) . ' ';
+
// Billed
- print ''.$langs->trans("Billed").' : '.price($sign * $object->total_ttc).' ';
-
+ print '' . $langs->trans("Billed") . ' : ' . price($sign * $object->total_ttc) . ' ';
+
// Remainder to pay back
- print '';
- if ($resteapayeraffiche <= 0) print $langs->trans('RemainderToPayBack');
- else print $langs->trans('ExcessPaydBack');
+ print ' ';
+ if ($resteapayeraffiche <= 0)
+ print $langs->trans('RemainderToPayBack');
+ else
+ print $langs->trans('ExcessPaydBack');
print ' : ';
- print ''.price($sign * $resteapayeraffiche).' ';
+ print '' . price($sign * $resteapayeraffiche) . ' ';
print ' ';
-
+
// Sold credit note
- //print ''.$langs->trans('TotalTTC').' : ';
- //print ''.price($sign * $object->total_ttc).' ';
+ // print ''.$langs->trans('TotalTTC').' : ';
+ // print ''.price($sign *
+ // $object->total_ttc).' ';
}
-
+
print '
';
-
+
// Margin Infos
- if (! empty($conf->margin->enabled))
- {
+ if (! empty($conf->margin->enabled)) {
print ' ';
$object->displayMarginInfos($object->statut > 0);
}
-
+
print ' ';
-
+
// Conditions de reglement
print '';
print '';
print ' ';
- if ($object->type != 2)
- {
- if ($action == 'editconditions')
- {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'cond_reglement_id');
+ if ($object->type != 2) {
+ if ($action == 'editconditions') {
+ $form->form_conditions_reglement($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
+ } else {
+ $form->form_conditions_reglement($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'none');
}
- else
- {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'none');
- }
- }
- else
- {
+ } else {
print ' ';
}
print ' ';
-
+
// Date payment term
print '';
print '';
print ' ';
- if ($object->type != 2)
- {
- if ($action == 'editpaymentterm')
- {
- $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date_lim_reglement,'paymentterm');
+ if ($object->type != 2) {
+ if ($action == 'editpaymentterm') {
+ $form->form_date($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->date_lim_reglement, 'paymentterm');
+ } else {
+ print dol_print_date($object->date_lim_reglement, 'daytext');
+ if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == 1 && ! isset($object->am))
+ print img_warning($langs->trans('Late'));
}
- else
- {
- print dol_print_date($object->date_lim_reglement,'daytext');
- if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == 1 && ! isset($object->am)) print img_warning($langs->trans('Late'));
- }
- }
- else
- {
+ } else {
print ' ';
}
print ' ';
-
+
// Payment mode
print '';
print '';
print ' ';
- if ($action == 'editmode')
- {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
- }
- else
- {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'none');
+ if ($action == 'editmode') {
+ $form->form_modes_reglement($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id');
+ } else {
+ $form->form_modes_reglement($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->mode_reglement_id, 'none');
}
print ' ';
-
+
// Amount
- print ''.$langs->trans('AmountHT').' ';
- print ''.price($object->total_ht,1,'',1,-1,-1,$conf->currency).' ';
- print ''.$langs->trans('AmountVAT').' '.price($object->total_tva,1,'',1,-1,-1,$conf->currency).' ';
+ print '' . $langs->trans('AmountHT') . ' ';
+ print '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
+ print '' . $langs->trans('AmountVAT') . ' ' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
print '';
-
+
// Amount Local Taxes
- if ($mysoc->localtax1_assuj=="1" && $mysoc->useLocalTax(1)) //Localtax1 (example RE)
+ if ($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) // Localtax1 (example RE)
{
- print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).' ';
- print ''.price($object->total_localtax1,1,'',1,-1,-1,$conf->currency).' ';
+ print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . ' ';
+ print '' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
}
- if ($mysoc->localtax2_assuj=="1" && $mysoc->useLocalTax(2)) //Localtax2 (example IRPF)
+ if ($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) // Localtax2 (example IRPF)
{
- print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).' ';
- print ''.price($object->total_localtax2,1,'',1,-1,-1,$conf->currency).' ';
+ print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ' ';
+ print '' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
}
-
+
// Revenue stamp
- if ($selleruserevenustamp) // Test company use revenue stamp
+ if ($selleruserevenustamp) // Test company use revenue stamp
{
print '';
print '';
print ' ';
- if ($action == 'editrevenuestamp')
- {
- print 'id.'" method="post">';
- print ' ';
+ if ($action == 'editrevenuestamp') {
+ print ' id . '" method="post">';
+ print ' ';
print ' ';
print $formother->select_revenue_stamp(GETPOST('revenuestamp'), 'revenuestamp', $mysoc->country_code);
- //print ' ';
- print ' ';
+ // print ' ';
+ print ' ';
print ' ';
- }
- else
- {
- print price($object->revenuestamp,1,'',1,-1,-1,$conf->currency);
+ } else {
+ print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
}
print ' ';
}
-
+
// Total with tax
- print ''.$langs->trans('AmountTTC').' '.price($object->total_ttc,1,'',1,-1,-1,$conf->currency).' ';
-
+ print '' . $langs->trans('AmountTTC') . ' ' . price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) . ' ';
+
// Statut
- print ''.$langs->trans('Status').' ';
- print ''.($object->getLibStatut(4,$totalpaye)).' ';
-
+ print '' . $langs->trans('Status') . ' ';
+ print '' . ($object->getLibStatut(4, $totalpaye)) . ' ';
+
// Project
- if (! empty($conf->projet->enabled))
- {
+ if (! empty($conf->projet->enabled)) {
$langs->load('projects');
print '';
print '';
-
+
print '';
-
+
print ' ';
- if ($action == 'classify')
- {
- $form->form_project($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->socid,$object->fk_project,'projectid');
- }
- else
- {
- $form->form_project($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->socid,$object->fk_project,'none');
+ if ($action == 'classify') {
+ $form->form_project($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'projectid');
+ } else {
+ $form->form_project($_SERVER ['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'none');
}
print ' ';
print ' ';
}
-
+
// Other attributes (TODO Move this into an include)
- $res=$object->fetch_optionals($object->id,$extralabels);
- $parameters=array('colspan' => ' colspan="2"');
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook) && ! empty($extrafields->attribute_label))
- {
-
- foreach($extrafields->attribute_label as $key=>$label)
- {
+ $res = $object->fetch_optionals($object->id, $extralabels);
+ $parameters = array('colspan' => ' colspan="2"');
+ $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
+ // hook
+ if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+
+ foreach ($extrafields->attribute_label as $key => $label) {
if ($action == 'edit_extras') {
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
+ $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
} else {
- $value=$object->array_options["options_".$key];
+ $value = $object->array_options ["options_" . $key];
}
- if ($extrafields->attribute_type[$key] == 'separate')
- {
+ if ($extrafields->attribute_type [$key] == 'separate') {
print $extrafields->showSeparator($key);
- }
- else
- {
+ } else {
print 'attribute_required[$key])) print ' class="fieldrequired"';
- print '>'.$label.' ';
+ if (! empty($extrafields->attribute_required [$key]))
+ print ' class="fieldrequired"';
+ print '>' . $label . ' ';
// Convert date into timestamp format
- if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
- {
- $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]);
+ if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) {
+ $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]);
}
-
- if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key)
- {
- print '';
+
+ if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key) {
+ print ' ';
print ' ';
- print ' ';
- print ' ';
- print ' ';
-
- print $extrafields->showInputField($key,$value);
-
- print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+
+ print $extrafields->showInputField($key, $value);
+
+ print ' ';
print ' ';
+ } else {
+ print $extrafields->showOutputField($key, $value);
+ if ($object->statut == 0 && $user->rights->facture->creer)
+ print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ' ';
}
- else
- {
- print $extrafields->showOutputField($key,$value);
- if ($object->statut == 0 && $user->rights->facture->creer) print ''.img_picto('','edit').' '.$langs->trans('Modify').' ';
- }
- print ' '."\n";
+ print '' . "\n";
}
}
}
-
+
print '
';
-
- if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
- {
+
+ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
$blocname = 'contacts';
$title = $langs->trans('ContactsAddresses');
- include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+ include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
}
-
- if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
- {
+
+ if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
$blocname = 'notes';
$title = $langs->trans('Notes');
- include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+ include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
}
-
+
// Lines
$result = $object->getLinesArray();
-
-
- print ' id.(($action != 'editline')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
-
-
+
+ print ' id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
+
+
-
+
';
-
-
- if (! empty($conf->use_javascript_ajax) && $object->statut == 0)
- {
- include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
+
+ if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
+ include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
}
-
+
print '';
-
+
// Show object lines
if (! empty($object->lines))
- $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1);
-
- // Form to add new line
- if ($object->statut == 0 && $user->rights->facture->creer && $action <> 'valid' && $action <> 'editline')
- {
- $var=true;
-
- if ($conf->global->MAIN_FEATURES_LEVEL > 1)
- {
+ $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
+
+ // Form to add new line
+ if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline') {
+ $var = true;
+
+ if ($conf->global->MAIN_FEATURES_LEVEL > 1) {
// Add free or predefined products/services
- $object->formAddObjectLine(1,$mysoc,$soc);
- }
- else
- {
+ $object->formAddObjectLine(1, $mysoc, $soc);
+ } else {
// Add free products/services
- $object->formAddFreeProduct(1,$mysoc,$soc);
-
+ $object->formAddFreeProduct(1, $mysoc, $soc);
+
// Add predefined products/services
- if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
- {
- $var=!$var;
- $object->formAddPredefinedProduct(1,$mysoc,$soc);
+ if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) {
+ $var = ! $var;
+ $object->formAddPredefinedProduct(1, $mysoc, $soc);
}
}
-
- $parameters=array();
- $reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by
+ // hook
}
-
+
print "
\n";
-
+
print " \n";
-
+
dol_fiche_end();
-
-
+
// Boutons actions
-
- if ($action != 'prerelance' && $action != 'presend' && $action != 'valid' && $action != 'editline')
- {
+
+ if ($action != 'prerelance' && $action != 'presend' && $action != 'valid' && $action != 'editline') {
print '';
-
- $parameters=array();
- $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- if (empty($reshook))
- {
+
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
+ // modified by hook
+ if (empty($reshook)) {
// Editer une facture deja validee, sans paiement effectue et pas exporte en compta
- if ($object->statut == 1)
- {
+ if ($object->statut == 1) {
// On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
$ventilExportCompta = $object->getVentilExportCompta();
-
- if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
- {
- if (! $objectidnext)
- {
- if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate)
- {
- print '
';
+
+ if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) {
+ if (! $objectidnext) {
+ if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate) {
+ print '
';
+ } else {
+ print '
' . $langs->trans('Modify') . '
';
}
- else
- {
- print '
'.$langs->trans('Modify').'
';
- }
- }
- else
- {
- print '
'.$langs->trans('Modify').'
';
+ } else {
+ print '
' . $langs->trans('Modify') . '
';
}
}
}
-
+
// Reopen a standard paid invoice
- if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3) && $user->rights->facture->creer) // A paid invoice (partially or completely)
+ if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3) && $user->rights->facture->creer) // A paid
+ // invoice
+ // (partially or
+ // completely)
{
- if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice
+ if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice
{
- print '
';
- }
- else
- {
- print '
'.$langs->trans('ReOpen').'
';
+ print '
';
+ } else {
+ print '
' . $langs->trans('ReOpen') . '
';
}
}
-
+
// Validate
- if ($object->statut == 0 && count($object->lines) > 0 &&
- (
- (($object->type == 0 || $object->type == 1 || $object->type == 3 || $object->type == 4) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0))
- || ($object->type == 2 && $object->total_ttc <= 0))
- )
- {
- if ($user->rights->facture->valider)
- {
- print '
';
+ if ($object->statut == 0 && count($object->lines) > 0 && ((($object->type == 0 || $object->type == 1 || $object->type == 3 || $object->type == 4) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0)) || ($object->type == 2 && $object->total_ttc <= 0))) {
+ if ($user->rights->facture->valider) {
+ print '
';
}
}
-
+
// Send by mail
- if (($object->statut == 1 || $object->statut == 2))
- {
- if ($objectidnext)
- {
- print '
'.$langs->trans('SendByMail').'
';
- }
- else
- {
- if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
- {
- print '
';
- }
- else print '
';
+ if (($object->statut == 1 || $object->statut == 2)) {
+ if ($objectidnext) {
+ print '
' . $langs->trans('SendByMail') . '
';
+ } else {
+ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send) {
+ print '
';
+ } else
+ print '
';
}
}
-
- if (! empty($conf->global->FACTURE_SHOW_SEND_REMINDER)) // For backward compatibility
+
+ if (! empty($conf->global->FACTURE_SHOW_SEND_REMINDER)) // For backward compatibility
{
- if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0)
- {
- if ($objectidnext)
- {
- print '
'.$langs->trans('SendRemindByMail').'
';
- }
- else
- {
- if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
- {
- print '
';
- }
- else print '
';
+ if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0) {
+ if ($objectidnext) {
+ print '
' . $langs->trans('SendRemindByMail') . '
';
+ } else {
+ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send) {
+ print '
';
+ } else
+ print '
';
}
}
}
-
+
// Create payment
- if ($object->type != 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
- {
- if ($objectidnext)
- {
- print '
'.$langs->trans('DoPayment').'
';
- }
- else
- {
- if ($resteapayer == 0)
- {
- print '
'.$langs->trans('DoPayment').'
';
- }
- else
- {
- print '
';
+ if ($object->type != 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) {
+ if ($objectidnext) {
+ print '
' . $langs->trans('DoPayment') . '
';
+ } else {
+ if ($resteapayer == 0) {
+ print '
' . $langs->trans('DoPayment') . '
';
+ } else {
+ print '
';
}
}
}
-
+
// Reverse back money or convert to reduction
- if ($object->type == 2 || $object->type == 3)
- {
+ if ($object->type == 2 || $object->type == 3) {
// For credit note only
- if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
- {
- print '
';
+ if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) {
+ print '
';
}
// For credit note
- if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0)
- {
- print '
';
+ if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) {
+ print '
';
}
// For deposit invoice
- if ($object->type == 3 && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer)
- {
- print '
';
+ if ($object->type == 3 && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer) {
+ print '
';
}
}
-
+
// Classify paid (if not deposit and not credit note. Such invoice are "converted")
- if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement &&
- (($object->type != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0)) )
- {
- print '
';
+ if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0))) {
+ print '
';
}
-
+
// Classify 'closed not completely paid' (possible si validee et pas encore classee payee)
- if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0
- && $user->rights->facture->paiement)
- {
- if ($totalpaye > 0 || $totalcreditnotes > 0)
- {
+ if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0 && $user->rights->facture->paiement) {
+ if ($totalpaye > 0 || $totalcreditnotes > 0) {
// If one payment or one credit note was linked to this invoice
- print '
';
- }
- else
- {
- if ($objectidnext)
- {
- print '
'.$langs->trans('ClassifyCanceled').'
';
- }
- else
- {
- print '
';
+ print '
';
+ } else {
+ if ($objectidnext) {
+ print '
' . $langs->trans('ClassifyCanceled') . '
';
+ } else {
+ print '
';
}
}
}
-
+
// Clone
- if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $user->rights->facture->creer)
- {
- print '
';
+ if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $user->rights->facture->creer) {
+ print '
';
}
-
+
// Clone as predefined
- if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $object->statut == 0 && $user->rights->facture->creer)
- {
- if (! $objectidnext)
- {
- print '
';
+ if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $object->statut == 0 && $user->rights->facture->creer) {
+ if (! $objectidnext) {
+ print '
';
}
}
-
+
// Delete
- if ($user->rights->facture->supprimer)
- {
- if (! $object->is_erasable())
- {
- print '
';
- }
- else if ($objectidnext)
- {
- print '
';
- }
- elseif ($object->getSommePaiement())
- {
- print '
';
- }
- else
- {
- print '
';
+ if ($user->rights->facture->supprimer) {
+ if (! $object->is_erasable()) {
+ print '
';
+ } else if ($objectidnext) {
+ print '
';
+ } elseif ($object->getSommePaiement()) {
+ print '
';
+ } else {
+ print '
';
}
+ } else {
+ print '
';
}
- else
- {
- print '
';
- }
-
+
print '
';
}
}
print ' ';
-
- if ($action != 'prerelance' && $action != 'presend')
- {
+
+ if ($action != 'prerelance' && $action != 'presend') {
print '';
print '
'; // ancre
-
+
// Documents generes
- $filename=dol_sanitizeFileName($object->ref);
- $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
- $urlsource=$_SERVER['PHP_SELF'].'?facid='.$object->id;
- $genallowed=$user->rights->facture->creer;
- $delallowed=$user->rights->facture->supprimer;
-
- print $formfile->showdocuments('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
- $somethingshown=$formfile->numoffiles;
-
+ $filename = dol_sanitizeFileName($object->ref);
+ $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
+ $urlsource = $_SERVER ['PHP_SELF'] . '?facid=' . $object->id;
+ $genallowed = $user->rights->facture->creer;
+ $delallowed = $user->rights->facture->supprimer;
+
+ print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
+ $somethingshown = $formfile->numoffiles;
+
// Linked object block
- $somethingshown=$object->showLinkedObjectBlock();
-
- if (empty($somethingshown) && $object->statut > 0)
- {
- print '
'.$langs->trans('LinkedOrder').' ';
-
+ $somethingshown = $object->showLinkedObjectBlock();
+
+ if (empty($somethingshown) && $object->statut > 0) {
+ print '
' . $langs->trans('LinkedOrder') . ' ';
+
print '
';
}
-
+
// Link for paypal payment
- if (! empty($conf->paypal->enabled) && $object->statut != 0)
- {
- include_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
- print showPaypalPaymentUrl('invoice',$object->ref);
+ if (! empty($conf->paypal->enabled) && $object->statut != 0) {
+ include_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php';
+ print showPaypalPaymentUrl('invoice', $object->ref);
}
-
+
print '
';
-
+
// List of actions on element
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
- $formactions=new FormActions($db);
- $somethingshown=$formactions->showactions($object,'invoice',$socid);
-
+ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
+ $formactions = new FormActions($db);
+ $somethingshown = $formactions->showactions($object, 'invoice', $socid);
+
print '
';
- }
- else
- {
+ } else {
/*
* Affiche formulaire mail
*/
-
+
// By default if $action=='presend'
- $titreform='SendBillByMail';
- $topicmail='SendBillRef';
- $modelmail='facture_send';
-
- if ($action == 'prerelance') // For backward compatibility
+ $titreform = 'SendBillByMail';
+ $topicmail = 'SendBillRef';
+ $modelmail = 'facture_send';
+
+ if ($action == 'prerelance') // For backward compatibility
{
- $titrefrom='SendReminderBillByMail';
- $topicmail='SendReminderBillRef';
- $modelmail='facture_relance';
- $action='relance';
- }
- else $action='send';
-
+ $titrefrom = 'SendReminderBillByMail';
+ $topicmail = 'SendReminderBillRef';
+ $modelmail = 'facture_relance';
+ $action = 'relance';
+ } else
+ $action = 'send';
+
$ref = dol_sanitizeFileName($object->ref);
- include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref,'/'));
- $file=$fileparams['fullname'];
-
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
+ $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/'));
+ $file = $fileparams ['fullname'];
+
// Build document if it not exists
- if (! $file || ! is_readable($file))
- {
+ if (! $file || ! is_readable($file)) {
// Define output language
$outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST ['lang_id']))
+ $newlang = $_REQUEST ['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->client->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
- $result=facture_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
+
+ $result = facture_pdf_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($result <= 0) {
+ dol_print_error($db, $result);
+ exit();
}
- $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref,'/'));
- $file=$fileparams['fullname'];
+ $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/'));
+ $file = $fileparams ['fullname'];
}
-
+
print ' ';
print_titre($langs->trans($titreform));
-
+
// Cree l'objet formulaire mail
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->fromtype = 'user';
- $formmail->fromid = $user->id;
+ $formmail->fromid = $user->id;
$formmail->fromname = $user->getFullName($langs);
$formmail->frommail = $user->email;
- $formmail->withfrom=1;
- $liste=array();
- foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)
- {
- $liste[$key]=$value;
+ $formmail->withfrom = 1;
+ $liste = array();
+ foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
+ $liste [$key] = $value;
}
- $formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$liste; // List suggested for send to
- $formmail->withtocc=$liste; // List suggested for CC
- $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
- if(empty($object->ref_client))
- {
- $formmail->withtopic=$langs->transnoentities($topicmail,'__FACREF__');
+ $formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste; // List suggested for send to
+ $formmail->withtocc = $liste; // List suggested for CC
+ $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
+ if (empty($object->ref_client)) {
+ $formmail->withtopic = $langs->transnoentities($topicmail, '__FACREF__');
+ } else if (! empty($object->ref_client)) {
+ $formmail->withtopic = $langs->transnoentities($topicmail, '__FACREF__(__REFCLIENT__)');
}
- else if(!empty($object->ref_client))
- {
- $formmail->withtopic=$langs->transnoentities($topicmail,'__FACREF__(__REFCLIENT__)');
- }
- $formmail->withfile=2;
- $formmail->withbody=1;
- $formmail->withdeliveryreceipt=1;
- $formmail->withcancel=1;
+ $formmail->withfile = 2;
+ $formmail->withbody = 1;
+ $formmail->withdeliveryreceipt = 1;
+ $formmail->withcancel = 1;
// Tableau des substitutions
- $formmail->substit['__FACREF__']=$object->ref;
- $formmail->substit['__SIGNATURE__']=$user->signature;
- $formmail->substit['__REFCLIENT__']=$object->ref_client;
- $formmail->substit['__PERSONALIZED__']='';
- $formmail->substit['__CONTACTCIVNAME__']='';
-
- //Find the good contact adress
- $custcontact='';
- $contactarr=array();
- $contactarr=$object->liste_contact(-1,'external');
-
- if (is_array($contactarr) && count($contactarr)>0) {
- foreach($contactarr as $contact) {
- if ($contact['libelle']==$langs->trans('TypeContact_facture_external_BILLING')) {
-
+ $formmail->substit ['__FACREF__'] = $object->ref;
+ $formmail->substit ['__SIGNATURE__'] = $user->signature;
+ $formmail->substit ['__REFCLIENT__'] = $object->ref_client;
+ $formmail->substit ['__PERSONALIZED__'] = '';
+ $formmail->substit ['__CONTACTCIVNAME__'] = '';
+
+ // Find the good contact adress
+ $custcontact = '';
+ $contactarr = array();
+ $contactarr = $object->liste_contact(- 1, 'external');
+
+ if (is_array($contactarr) && count($contactarr) > 0) {
+ foreach ($contactarr as $contact) {
+ if ($contact ['libelle'] == $langs->trans('TypeContact_facture_external_BILLING')) {
+
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
-
- $contactstatic=new Contact($db);
- $contactstatic->fetch($contact['id']);
- $custcontact=$contactstatic->getFullName($langs,1);
+
+ $contactstatic = new Contact($db);
+ $contactstatic->fetch($contact ['id']);
+ $custcontact = $contactstatic->getFullName($langs, 1);
}
}
-
- if (!empty($custcontact)) {
- $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
+
+ if (! empty($custcontact)) {
+ $formmail->substit ['__CONTACTCIVNAME__'] = $custcontact;
}
}
-
-
+
// Tableau des parametres complementaires du post
- $formmail->param['action']=$action;
- $formmail->param['models']=$modelmail;
- $formmail->param['facid']=$object->id;
- $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
-
+ $formmail->param ['action'] = $action;
+ $formmail->param ['models'] = $modelmail;
+ $formmail->param ['facid'] = $object->id;
+ $formmail->param ['returnurl'] = $_SERVER ["PHP_SELF"] . '?id=' . $object->id;
+
// Init list of files
- if (GETPOST("mode")=='init')
- {
+ if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
- $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
+ $formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
-
+
print $formmail->get_form();
-
+
print ' ';
}
}
-dol_htmloutput_mesg('',$mesgs);
+dol_htmloutput_mesg('', $mesgs);
llxFooter();
$db->close();
diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php
index 990b154d0eb..1ef0ef48191 100644
--- a/htdocs/product/ajax/products.php
+++ b/htdocs/product/ajax/products.php
@@ -18,183 +18,176 @@
*/
/**
- * \file htdocs/product/ajax/products.php
- * \brief File to return Ajax response on product list request
+ * \file htdocs/product/ajax/products.php
+ * \brief File to return Ajax response on product list request
*/
-
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
-if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
-if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
-if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
-if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
-if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
-if (empty($_GET['keysearch']) && ! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
+if (! defined('NOTOKENRENEWAL'))
+ define('NOTOKENRENEWAL', 1); // Disables token renewal
+if (! defined('NOREQUIREMENU'))
+ define('NOREQUIREMENU', '1');
+if (! defined('NOREQUIREHTML'))
+ define('NOREQUIREHTML', '1');
+if (! defined('NOREQUIREAJAX'))
+ define('NOREQUIREAJAX', '1');
+if (! defined('NOREQUIRESOC'))
+ define('NOREQUIRESOC', '1');
+if (! defined('NOCSRFCHECK'))
+ define('NOCSRFCHECK', '1');
+if (empty($_GET ['keysearch']) && ! defined('NOREQUIREHTML'))
+ define('NOREQUIREHTML', '1');
require '../../main.inc.php';
-$htmlname=GETPOST('htmlname','alpha');
-$socid=GETPOST('socid','int');
-$type=GETPOST('type','int');
-$mode=GETPOST('mode','int');
-$status=((GETPOST('status','int') >= 0) ? GETPOST('status','int') : -1);
-$outjson=(GETPOST('outjson','int') ? GETPOST('outjson','int') : 0);
-$price_level=GETPOST('price_level','int');
-$action=GETPOST('action', 'alpha');
-$id=GETPOST('id', 'int');
-$price_by_qty_rowid=GETPOST('pbq', 'int');
+$htmlname = GETPOST('htmlname', 'alpha');
+$socid = GETPOST('socid', 'int');
+$type = GETPOST('type', 'int');
+$mode = GETPOST('mode', 'int');
+$status = ((GETPOST('status', 'int') >= 0) ? GETPOST('status', 'int') : - 1);
+$outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
+$price_level = GETPOST('price_level', 'int');
+$action = GETPOST('action', 'alpha');
+$id = GETPOST('id', 'int');
+$price_by_qty_rowid = GETPOST('pbq', 'int');
/*
* View
*/
-//print ''."\n";
+// print ''."\n";
-dol_syslog(join(',',$_GET));
-//print_r($_GET);
+dol_syslog(join(',', $_GET));
+// print_r($_GET);
-if (! empty($action) && $action == 'fetch' && ! empty($id))
-{
+if (! empty($action) && $action == 'fetch' && ! empty($id)) {
require DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
-
- $outjson=array();
-
+
+ $outjson = array();
+
$object = new Product($db);
- $ret=$object->fetch($id);
- if ($ret > 0)
- {
- $outref=$object->ref;
- $outlabel=$object->label;
- $outdesc=$object->description;
- $outtype=$object->type;
- $outqty=1;
- $outdiscount=0;
-
- $found=false;
-
+ $ret = $object->fetch($id);
+ if ($ret > 0) {
+ $outref = $object->ref;
+ $outlabel = $object->label;
+ $outdesc = $object->description;
+ $outtype = $object->type;
+ $outqty = 1;
+ $outdiscount = 0;
+
+ $found = false;
+
// Price by qty
- if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))) // If we need a particular price related to qty
+ if (! empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))) // If we need a
+ // particular price related
+ // to qty
{
$sql = "SELECT price, unitprice, quantity, remise_percent";
- $sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty ";
- $sql.= " WHERE rowid=".$price_by_qty_rowid."";
-
+ $sql .= " FROM " . MAIN_DB_PREFIX . "product_price_by_qty ";
+ $sql .= " WHERE rowid=" . $price_by_qty_rowid . "";
+
$result = $db->query($sql);
- if ($result)
- {
+ if ($result) {
$objp = $db->fetch_object($result);
- if ($objp)
- {
- $found=true;
- $outprice_ht=price($objp->unitprice);
- $outprice_ttc=price($objp->unitprice * (1 + ($object->tva_tx / 100)));
- $outpricebasetype=$object->price_base_type;
- $outtva_tx=$object->tva_tx;
- $outqty=$objp->quantity;
- $outdiscount=$objp->remise_percent;
+ if ($objp) {
+ $found = true;
+ $outprice_ht = price($objp->unitprice);
+ $outprice_ttc = price($objp->unitprice * (1 + ($object->tva_tx / 100)));
+ $outpricebasetype = $object->price_base_type;
+ $outtva_tx = $object->tva_tx;
+ $outqty = $objp->quantity;
+ $outdiscount = $objp->remise_percent;
}
}
}
-
+
// Multiprice
- if (! $found && isset($price_level) && $price_level >= 1 && (! empty($conf->global->PRODUIT_MULTIPRICES))) // If we need a particular price level (from 1 to 6)
+ if (! $found && isset($price_level) && $price_level >= 1 && (! empty($conf->global->PRODUIT_MULTIPRICES))) // If we need a particular price
+ // level (from 1 to 6)
{
$sql = "SELECT price, price_ttc, price_base_type, tva_tx";
- $sql.= " FROM ".MAIN_DB_PREFIX."product_price ";
- $sql.= " WHERE fk_product='".$id."'";
- $sql.= " AND entity IN (".getEntity('productprice', 1).")";
- $sql.= " AND price_level=".$price_level;
- $sql.= " ORDER BY date_price";
- $sql.= " DESC LIMIT 1";
-
+ $sql .= " FROM " . MAIN_DB_PREFIX . "product_price ";
+ $sql .= " WHERE fk_product='" . $id . "'";
+ $sql .= " AND entity IN (" . getEntity('productprice', 1) . ")";
+ $sql .= " AND price_level=" . $price_level;
+ $sql .= " ORDER BY date_price";
+ $sql .= " DESC LIMIT 1";
+
$result = $db->query($sql);
- if ($result)
- {
+ if ($result) {
$objp = $db->fetch_object($result);
- if ($objp)
- {
- $found=true;
- $outprice_ht=price($objp->price);
- $outprice_ttc=price($objp->price_ttc);
- $outpricebasetype=$objp->price_base_type;
- $outtva_tx=$objp->tva_tx;
+ if ($objp) {
+ $found = true;
+ $outprice_ht = price($objp->price);
+ $outprice_ttc = price($objp->price_ttc);
+ $outpricebasetype = $objp->price_base_type;
+ $outtva_tx = $objp->tva_tx;
}
}
}
- //Price by customer
- if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
-
+ // Price by customer
+ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && ! empty($socid)) {
+
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
-
- $prodcustprice = new Productcustomerprice ( $db );
-
- $filter = array (
- 't.fk_product' => $object->id,
- 't.fk_soc'=> $socid
- );
-
- $result = $prodcustprice->fetch_all ( '', '', 0,0, $filter );
- if ($result)
- {
- if (count($prodcustprice->lines)>0)
- {
- $found=true;
- $outprice_ht=price($prodcustprice->lines[0]->price);
- $outprice_ttc=price($prodcustprice->lines[0]->price_ttc);
- $outpricebasetype=$prodcustprice->lines[0]->price_base_type;
- $outtva_tx=$prodcustprice->lines[0]->tva_tx;
+
+ $prodcustprice = new Productcustomerprice($db);
+
+ $filter = array('t.fk_product' => $object->id,'t.fk_soc' => $socid);
+
+ $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
+ if ($result) {
+ if (count($prodcustprice->lines) > 0) {
+ $found = true;
+ $outprice_ht = price($prodcustprice->lines [0]->price);
+ $outprice_ttc = price($prodcustprice->lines [0]->price_ttc);
+ $outpricebasetype = $prodcustprice->lines [0]->price_base_type;
+ $outtva_tx = $prodcustprice->lines [0]->tva_tx;
}
}
}
-
- if (! $found)
- {
- $outprice_ht=price($object->price);
- $outprice_ttc=price($object->price_ttc);
- $outpricebasetype=$object->price_base_type;
- $outtva_tx=$object->tva_tx;
+ if (! $found) {
+ $outprice_ht = price($object->price);
+ $outprice_ttc = price($object->price_ttc);
+ $outpricebasetype = $object->price_base_type;
+ $outtva_tx = $object->tva_tx;
}
-
- $outjson = array('ref'=>$outref, 'label'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>$outprice_ht, 'price_ttc'=>$outprice_ttc, 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx, 'qty'=>$outqty, 'discount'=>$outdiscount);
+
+ $outjson = array('ref' => $outref,'label' => $outlabel,'desc' => $outdesc,'type' => $outtype,'price_ht' => $outprice_ht,'price_ttc' => $outprice_ttc,'pricebasetype' => $outpricebasetype,'tva_tx' => $outtva_tx,'qty' => $outqty,'discount' => $outdiscount);
}
-
+
echo json_encode($outjson);
-
-}
-else
-{
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
-
+} else {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
+
$langs->load("products");
$langs->load("main");
-
+
top_httphead();
-
- if (empty($htmlname)) return;
-
- $match = preg_grep('/('.$htmlname.'[0-9]+)/',array_keys($_GET));
+
+ if (empty($htmlname))
+ return;
+
+ $match = preg_grep('/(' . $htmlname . '[0-9]+)/', array_keys($_GET));
sort($match);
- $idprod = (! empty($match[0]) ? $match[0] : '');
-
- if (! GETPOST($htmlname) && ! GETPOST($idprod)) return;
-
- // When used from jQuery, the search term is added as GET param "term".
- $searchkey=(GETPOST($idprod)?GETPOST($idprod):(GETPOST($htmlname)?GETPOST($htmlname):''));
-
+ $idprod = (! empty($match [0]) ? $match [0] : '');
+
+ if (! GETPOST($htmlname) && ! GETPOST($idprod))
+ return;
+
+ // When used from jQuery, the search term is added as GET param "term".
+ $searchkey = (GETPOST($idprod) ? GETPOST($idprod) : (GETPOST($htmlname) ? GETPOST($htmlname) : ''));
+
$form = new Form($db);
- if (empty($mode) || $mode == 1)
- {
- $arrayresult=$form->select_produits_list("",$htmlname,$type,"",$price_level,$searchkey,$status,2,$outjson,$socid);
+ if (empty($mode) || $mode == 1) {
+ $arrayresult = $form->select_produits_list("", $htmlname, $type, "", $price_level, $searchkey, $status, 2, $outjson, $socid);
+ } elseif ($mode == 2) {
+ $arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson, $socid);
}
- elseif ($mode == 2)
- {
- $arrayresult=$form->select_produits_fournisseurs_list($socid,"",$htmlname,$type,"",$searchkey,$status,$outjson,$socid);
- }
-
+
$db->close();
-
- if ($outjson) print json_encode($arrayresult);
+
+ if ($outjson)
+ print json_encode($arrayresult);
}
?>
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index f510a0bf517..3970047a59f 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -21,33 +21,33 @@
*/
/**
- * \file htdocs/product/price.php
- * \ingroup product
- * \brief Page to show product prices
+ * \file htdocs/product/price.php
+ * \ingroup product
+ * \brief Page to show product prices
*/
-
require '../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
-if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
+if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
- $prodcustprice = new Productcustomerprice ( $db );
+ $prodcustprice = new Productcustomerprice($db);
}
$langs->load("products");
$langs->load("bills");
-$id = GETPOST('id', 'int');
-$ref = GETPOST('ref', 'alpha');
-$action = GETPOST('action', 'alpha');
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'alpha');
// Security check
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
-if ($user->societe_id) $socid=$user->societe_id;
-$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
+if ($user->societe_id)
+ $socid = $user->societe_id;
+$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
$object = new Product($db);
@@ -55,70 +55,62 @@ $object = new Product($db);
* Actions
*/
-if ($action == 'update_price' && ! $_POST["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer))
-{
+if ($action == 'update_price' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) {
$result = $object->fetch($id);
// MultiPrix
- if (! empty($conf->global->PRODUIT_MULTIPRICES))
- {
- $newprice='';
- $newprice_min='';
- $newpricebase='';
- $newvat='';
-
- for($i=1; $i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
- {
- if (isset($_POST["price_".$i]))
- {
- $level=$i;
- $newprice=price2num($_POST["price_".$i],'MU');
- $newprice_min=price2num($_POST["price_min_".$i],'MU');
- $newpricebase=$_POST["multiprices_base_type_".$i];
- $newnpr=(preg_match('/\*/',$_POST["tva_tx_".$i]) ? 1 : 0);
- $newvat=str_replace('*','',$_POST["tva_tx_".$i]);
- $newpsq=GETPOST('psqflag');
+ if (! empty($conf->global->PRODUIT_MULTIPRICES)) {
+ $newprice = '';
+ $newprice_min = '';
+ $newpricebase = '';
+ $newvat = '';
+
+ for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) {
+ if (isset($_POST ["price_" . $i])) {
+ $level = $i;
+ $newprice = price2num($_POST ["price_" . $i], 'MU');
+ $newprice_min = price2num($_POST ["price_min_" . $i], 'MU');
+ $newpricebase = $_POST ["multiprices_base_type_" . $i];
+ $newnpr = (preg_match('/\*/', $_POST ["tva_tx_" . $i]) ? 1 : 0);
+ $newvat = str_replace('*', '', $_POST ["tva_tx_" . $i]);
+ $newpsq = GETPOST('psqflag');
$newpsq = empty($newpsq) ? 0 : $newpsq;
- break; // We found submited price
+ break; // We found submited price
}
}
- }
- else
- {
- $level=0;
- $newprice=price2num($_POST["price"],'MU');
- $newprice_min=price2num($_POST["price_min"],'MU');
- $newpricebase=$_POST["price_base_type"];
- $newnpr=(preg_match('/\*/',$_POST["tva_tx"]) ? 1 : 0);
- $newvat=str_replace('*','',$_POST["tva_tx"]);
- $newpsq=GETPOST('psqflag');
+ } else {
+ $level = 0;
+ $newprice = price2num($_POST ["price"], 'MU');
+ $newprice_min = price2num($_POST ["price_min"], 'MU');
+ $newpricebase = $_POST ["price_base_type"];
+ $newnpr = (preg_match('/\*/', $_POST ["tva_tx"]) ? 1 : 0);
+ $newvat = str_replace('*', '', $_POST ["tva_tx"]);
+ $newpsq = GETPOST('psqflag');
$newpsq = empty($newpsq) ? 0 : $newpsq;
}
-
- if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0)
- {
+
+ if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) {
$action = '';
- $mesg = ''.$langs->trans("RecordSaved").'
';
- }
- else
- {
+ $mesg = '' . $langs->trans("RecordSaved") . '
';
+ } else {
$action = 'edit_price';
- $mesg = ''.$object->error.'
';
+ $mesg = '' . $object->error . '
';
}
-}
-else if ($action == 'delete' && $user->rights->produit->supprimer)
-{
- $result=$object->log_price_delete($user,$_GET["lineid"]);
- if ($result < 0) $mesg=''.$object->error.'
';
+} else if ($action == 'delete' && $user->rights->produit->supprimer) {
+ $result = $object->log_price_delete($user, $_GET ["lineid"]);
+ if ($result < 0)
+ $mesg = '' . $object->error . '
';
}
-/*****************************************************
+/**
+ * ***************************************************
* Price by quantity
- *****************************************************/
-$error=0;
+ * ***************************************************
+ */
+$error = 0;
if ($action == 'activate_price_by_qty') { // Activating product price by quantity add a new price, specified as by quantity
$result = $object->fetch($id);
- $level=GETPOST('level');
+ $level = GETPOST('level');
$object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1);
}
@@ -129,51 +121,48 @@ if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité
if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par quantité
$result = $object->fetch($id);
-
+
// Récupération des variables
$rowid = GETPOST('rowid');
- $priceid=GETPOST('priceid');
- $newprice=price2num(GETPOST("price"),'MU');
- //$newminprice=price2num(GETPOST("price_min"),'MU'); // TODO : Add min price management
- $quantity=GETPOST('quantity');
- $remise_percent=price2num(GETPOST('remise_percent'));
- $remise=0; // TODO : allow dicsount by amount when available on documents
+ $priceid = GETPOST('priceid');
+ $newprice = price2num(GETPOST("price"), 'MU');
+ // $newminprice=price2num(GETPOST("price_min"),'MU'); // TODO : Add min price management
+ $quantity = GETPOST('quantity');
+ $remise_percent = price2num(GETPOST('remise_percent'));
+ $remise = 0; // TODO : allow dicsount by amount when available on documents
- if (empty($quantity))
- {
- $error++;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'
';
+ if (empty($quantity)) {
+ $error ++;
+ $mesg = '' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Qty")) . '
';
}
- if (empty($newprice))
- {
- $error++;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")).'
';
+ if (empty($newprice)) {
+ $error ++;
+ $mesg = '' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Price")) . '
';
}
- if(!$error) {
+ if (! $error) {
// Calcul du prix HT et du prix unitaire
- if ($object->price_base_type == 'TTC')
- {
+ if ($object->price_base_type == 'TTC') {
$price = price2num($newprice) / (1 + ($object->tva_tx / 100));
}
- $price = price2num($newprice,'MU');
- $unitPrice = price2num($price/$quantity,'MU');
-
+ $price = price2num($newprice, 'MU');
+ $unitPrice = price2num($price / $quantity, 'MU');
+
// Ajout / mise à jour
- if($rowid > 0) {
- $sql = "UPDATE ".MAIN_DB_PREFIX."product_price_by_qty SET";
- $sql.= " price='".$price."',";
- $sql.= " unitprice=".$unitPrice.",";
- $sql.= " quantity=".$quantity.",";
- $sql.= " remise_percent=".$remise_percent.",";
- $sql.= " remise=".$remise;
- $sql.= " WHERE rowid = ".GETPOST('rowid');
+ if ($rowid > 0) {
+ $sql = "UPDATE " . MAIN_DB_PREFIX . "product_price_by_qty SET";
+ $sql .= " price='" . $price . "',";
+ $sql .= " unitprice=" . $unitPrice . ",";
+ $sql .= " quantity=" . $quantity . ",";
+ $sql .= " remise_percent=" . $remise_percent . ",";
+ $sql .= " remise=" . $remise;
+ $sql .= " WHERE rowid = " . GETPOST('rowid');
$result = $db->query($sql);
} else {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
- $sql.= $priceid.','.$price.','.$unitPrice.','.$quantity.','.$remise_percent.','.$remise.')';
-
+ $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
+ $sql .= $priceid . ',' . $price . ',' . $unitPrice . ',' . $quantity . ',' . $remise_percent . ',' . $remise . ')';
+
$result = $db->query($sql);
}
}
@@ -182,264 +171,235 @@ if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par qu
if ($action == 'delete_price_by_qty') {
$rowid = GETPOST('rowid');
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
- $sql.= " WHERE rowid = ".GETPOST('rowid');
+ $sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_price_by_qty";
+ $sql .= " WHERE rowid = " . GETPOST('rowid');
$result = $db->query($sql);
}
if ($action == 'delete_all_price_by_qty') {
- $priceid=GETPOST('priceid');
+ $priceid = GETPOST('priceid');
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
- $sql.= " WHERE fk_product_price = ".$priceid;
+ $sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_price_by_qty";
+ $sql .= " WHERE fk_product_price = " . $priceid;
$result = $db->query($sql);
}
-/*****************************************************
+/**
+ * ***************************************************
* Price by customer
-*****************************************************/
-if ($action == 'add_customer_price_confirm' && ! $_POST["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer))
-{
+ * ****************************************************
+ */
+if ($action == 'add_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) {
- $update_child_soc=GETPOST('updatechildprice');
+ $update_child_soc = GETPOST('updatechildprice');
$result = $object->fetch($id);
- //add price by customer
- $prodcustprice->fk_soc=GETPOST('socid','int');
- $prodcustprice->fk_product=$object->id;
- $prodcustprice->price=price2num(GETPOST("price"),'MU');
- $prodcustprice->price_min=price2num(GETPOST("price_min"),'MU');
- $prodcustprice->price_base_type=GETPOST("price_base_type",'alpha');
- $prodcustprice->tva_tx=str_replace('*','',GETPOST("tva_tx"));
- $prodcustprice->recuperableonly=(preg_match('/\*/',GETPOST("tva_tx")) ? 1 : 0);
-
- $result = $prodcustprice->create($user,0,$update_child_soc);
-
- if ($result < 0)
- {
- setEventMessage($prodcustprice->error,'errors');
+ // add price by customer
+ $prodcustprice->fk_soc = GETPOST('socid', 'int');
+ $prodcustprice->fk_product = $object->id;
+ $prodcustprice->price = price2num(GETPOST("price"), 'MU');
+ $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
+ $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
+ $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx"));
+ $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0);
+
+ $result = $prodcustprice->create($user, 0, $update_child_soc);
+
+ if ($result < 0) {
+ setEventMessage($prodcustprice->error, 'errors');
} else {
- setEventMessage($langs->trans('Save'),'mesgs');
+ setEventMessage($langs->trans('Save'), 'mesgs');
}
-
- $action='';
+
+ $action = '';
}
-if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer))
-{
- //Delete price by customer
- $prodcustprice->id=GETPOST('lineid');
+if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) {
+ // Delete price by customer
+ $prodcustprice->id = GETPOST('lineid');
$result = $prodcustprice->delete($user);
-
- if ($result < 0)
- {
- setEventMessage($prodcustprice->error,'mesgs');
- }else {
- setEventMessage($langs->trans('Delete'),'errors');
+
+ if ($result < 0) {
+ setEventMessage($prodcustprice->error, 'mesgs');
+ } else {
+ setEventMessage($langs->trans('Delete'), 'errors');
}
- $action='';
+ $action = '';
}
-if ($action == 'update_customer_price_confirm' && ! $_POST["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer))
-{
+if ($action == 'update_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) {
- $update_child_soc=GETPOST('updatechildprice');
+ $update_child_soc = GETPOST('updatechildprice');
- $prodcustprice->fetch(GETPOST('lineid','int'));
+ $prodcustprice->fetch(GETPOST('lineid', 'int'));
- //update price by customer
- $prodcustprice->price=price2num(GETPOST("price"),'MU');
- $prodcustprice->price_min=price2num(GETPOST("price_min"),'MU');
- $prodcustprice->price_base_type=GETPOST("price_base_type",'alpha');
- $prodcustprice->tva_tx=str_replace('*','',GETPOST("tva_tx"));
- $prodcustprice->recuperableonly=(preg_match('/\*/',GETPOST("tva_tx")) ? 1 : 0);
-
- $result = $prodcustprice->update($user,0,$update_child_soc);
-
- if ($result < 0)
- {
- setEventMessage($prodcustprice->error,'errors');
- }else {
- setEventMessage($langs->trans('Save'),'mesgs');
+ // update price by customer
+ $prodcustprice->price = price2num(GETPOST("price"), 'MU');
+ $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
+ $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
+ $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx"));
+ $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0);
+
+ $result = $prodcustprice->update($user, 0, $update_child_soc);
+
+ if ($result < 0) {
+ setEventMessage($prodcustprice->error, 'errors');
+ } else {
+ setEventMessage($langs->trans('Save'), 'mesgs');
}
-
- $action='';
+
+ $action = '';
}
-
-
/*
* View
*/
$form = new Form($db);
-if (! empty($id) || ! empty($ref)) $result = $object->fetch($id, $ref);
+if (! empty($id) || ! empty($ref))
+ $result = $object->fetch($id, $ref);
-llxHeader("","",$langs->trans("CardProduct".$object->type));
+llxHeader("", "", $langs->trans("CardProduct" . $object->type));
-$head=product_prepare_head($object, $user);
-$titre=$langs->trans("CardProduct".$object->type);
-$picto=($object->type==1?'service':'product');
+$head = product_prepare_head($object, $user);
+$titre = $langs->trans("CardProduct" . $object->type);
+$picto = ($object->type == 1 ? 'service' : 'product');
dol_fiche_head($head, 'price', $titre, 0, $picto);
print '';
// Ref
print '';
-print ''.$langs->trans("Ref").' ';
-print $form->showrefnav($object,'ref','',1,'ref');
+print ' ' . $langs->trans("Ref") . ' ';
+print $form->showrefnav($object, 'ref', '', 1, 'ref');
print ' ';
print ' ';
// Label
-print ''.$langs->trans("Label").' '.$object->libelle.' ';
+print '' . $langs->trans("Label") . ' ' . $object->libelle . ' ';
-$isphoto=$object->is_photo_available($conf->product->multidir_output[$object->entity]);
+$isphoto = $object->is_photo_available($conf->product->multidir_output [$object->entity]);
-$nblignes=5;
-if ($isphoto)
-{
+$nblignes = 5;
+if ($isphoto) {
// Photo
- print '';
- print $object->show_photos($conf->product->multidir_output[$object->entity],1,1,0,0,0,80);
+ print ' ';
+ print $object->show_photos($conf->product->multidir_output [$object->entity], 1, 1, 0, 0, 0, 80);
print ' ';
}
print ' ';
// MultiPrix
-if (! empty($conf->global->PRODUIT_MULTIPRICES))
-{
- if (! empty($socid))
- {
+if (! empty($conf->global->PRODUIT_MULTIPRICES)) {
+ if (! empty($socid)) {
$soc = new Societe($db);
$soc->id = $socid;
$soc->fetch($socid);
-
- print ''.$langs->trans("SellingPrice").' ';
-
- if ($object->multiprices_base_type["$soc->price_level"] == 'TTC')
- {
- print ''.price($object->multiprices_ttc["$soc->price_level"]);
+
+ print ' ' . $langs->trans("SellingPrice") . ' ';
+
+ if ($object->multiprices_base_type ["$soc->price_level"] == 'TTC') {
+ print '' . price($object->multiprices_ttc ["$soc->price_level"]);
+ } else {
+ print ' ' . price($object->multiprices ["$soc->price_level"]);
}
- else
- {
- print ' '.price($object->multiprices["$soc->price_level"]);
- }
-
- if ($object->multiprices_base_type["$soc->price_level"])
- {
- print ' '.$langs->trans($object->multiprices_base_type["$soc->price_level"]);
- }
- else
- {
- print ' '.$langs->trans($object->price_base_type);
+
+ if ($object->multiprices_base_type ["$soc->price_level"]) {
+ print ' ' . $langs->trans($object->multiprices_base_type ["$soc->price_level"]);
+ } else {
+ print ' ' . $langs->trans($object->price_base_type);
}
print ' ';
-
+
// Prix mini
- print ''.$langs->trans("MinPrice").' ';
- if ($object->multiprices_base_type["$soc->price_level"] == 'TTC')
- {
- print price($object->multiprices_min_ttc["$soc->price_level"]).' '.$langs->trans($object->multiprices_base_type["$soc->price_level"]);
- }
- else
- {
- print price($object->multiprices_min["$soc->price_level"]).' '.$langs->trans($object->multiprices_base_type["$soc->price_level"]);
+ print ' ' . $langs->trans("MinPrice") . ' ';
+ if ($object->multiprices_base_type ["$soc->price_level"] == 'TTC') {
+ print price($object->multiprices_min_ttc ["$soc->price_level"]) . ' ' . $langs->trans($object->multiprices_base_type ["$soc->price_level"]);
+ } else {
+ print price($object->multiprices_min ["$soc->price_level"]) . ' ' . $langs->trans($object->multiprices_base_type ["$soc->price_level"]);
}
print ' ';
-
+
// TVA
- print ''.$langs->trans("VATRate").' '.vatrate($object->multiprices_tva_tx["$soc->price_level"],true).' ';
- }
- else
- {
- for ($i=1; $i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
- {
- // TVA
- if ($i == 1) // We show only price for level 1
- {
- print ''.$langs->trans("VATRate").' '.vatrate($object->multiprices_tva_tx[1],true).' ';
- }
-
- print ''.$langs->trans("SellingPrice").' '.$i.' ';
-
- if ($object->multiprices_base_type["$i"] == 'TTC')
+ print '' . $langs->trans("VATRate") . ' ' . vatrate($object->multiprices_tva_tx ["$soc->price_level"], true) . ' ';
+ } else {
+ for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) {
+ // TVA
+ if ($i == 1) // We show only price for level 1
{
- print ''.price($object->multiprices_ttc["$i"]);
+ print ' ' . $langs->trans("VATRate") . ' ' . vatrate($object->multiprices_tva_tx [1], true) . ' ';
}
- else
- {
- print ''.price($object->multiprices["$i"]);
+
+ print ' ' . $langs->trans("SellingPrice") . ' ' . $i . ' ';
+
+ if ($object->multiprices_base_type ["$i"] == 'TTC') {
+ print '' . price($object->multiprices_ttc ["$i"]);
+ } else {
+ print ' ' . price($object->multiprices ["$i"]);
}
-
- if ($object->multiprices_base_type["$i"])
- {
- print ' '.$langs->trans($object->multiprices_base_type["$i"]);
- }
- else
- {
- print ' '.$langs->trans($object->price_base_type);
+
+ if ($object->multiprices_base_type ["$i"]) {
+ print ' ' . $langs->trans($object->multiprices_base_type ["$i"]);
+ } else {
+ print ' ' . $langs->trans($object->price_base_type);
}
print ' ';
-
+
// Prix mini
- print ''.$langs->trans("MinPrice").' '.$i.' ';
- if ($object->multiprices_base_type["$i"] == 'TTC')
- {
- print price($object->multiprices_min_ttc["$i"]).' '.$langs->trans($object->multiprices_base_type["$i"]);
- }
- else
- {
- print price($object->multiprices_min["$i"]).' '.$langs->trans($object->multiprices_base_type["$i"]);
+ print ' ' . $langs->trans("MinPrice") . ' ' . $i . ' ';
+ if ($object->multiprices_base_type ["$i"] == 'TTC') {
+ print price($object->multiprices_min_ttc ["$i"]) . ' ' . $langs->trans($object->multiprices_base_type ["$i"]);
+ } else {
+ print price($object->multiprices_min ["$i"]) . ' ' . $langs->trans($object->multiprices_base_type ["$i"]);
}
print ' ';
-
+
// Price by quantity
- if($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) {
- print ''.$langs->trans("PriceByQuantity").' '.$i;
+ if ($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) {
+ print ' ' . $langs->trans("PriceByQuantity") . ' ' . $i;
print ' ';
- if($object->prices_by_qty[$i] == 1) {
+ if ($object->prices_by_qty [$i] == 1) {
print '';
} else {
print $langs->trans("No");
- print ' ('.$langs->trans("Activate").') ';
+ print ' (' . $langs->trans("Activate") . ') ';
}
print ' ';
}
}
}
-}
-else
-{
- // TVA
- print ''.$langs->trans("VATRate").' '.vatrate($object->tva_tx.($object->tva_npr?'*':''),true).' ';
-
- // Price
- print ''.$langs->trans("SellingPrice").' ';
- if ($object->price_base_type == 'TTC')
- {
- print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
- }
- else
- {
- print price($object->price).' '.$langs->trans($object->price_base_type);
+} else {
+ // TVA
+ print ' ' . $langs->trans("VATRate") . ' ' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . ' ';
+
+ // Price
+ print '' . $langs->trans("SellingPrice") . ' ';
+ if ($object->price_base_type == 'TTC') {
+ print price($object->price_ttc) . ' ' . $langs->trans($object->price_base_type);
+ } else {
+ print price($object->price) . ' ' . $langs->trans($object->price_base_type);
}
print ' ';
-
+
// Price minimum
- print ''.$langs->trans("MinPrice").' ';
- if ($object->price_base_type == 'TTC')
- {
- print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
- }
- else
- {
- print price($object->price_min).' '.$langs->trans($object->price_base_type);
+ print ' ' . $langs->trans("MinPrice") . ' ';
+ if ($object->price_base_type == 'TTC') {
+ print price($object->price_min_ttc) . ' ' . $langs->trans($object->price_base_type);
+ } else {
+ print price($object->price_min) . ' ' . $langs->trans($object->price_base_type);
}
print ' ';
// Price by quantity
- if($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)
- {
- print ''.$langs->trans("PriceByQuantity");
- if($object->prices_by_qty[0] == 0) {
- print ' '.$langs->trans("Activate");
+ if ($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) {
+ print '' . $langs->trans("PriceByQuantity");
+ if ($object->prices_by_qty [0] == 0) {
+ print ' ' . $langs->trans("Activate");
}
print ' ';
- if($object->prices_by_qty[0] == 1)
- {
+ if ($object->prices_by_qty [0] == 1) {
print '';
} else {
print $langs->trans("No");
@@ -578,8 +527,8 @@ else
}
// Status (to sell)
-print ' '.$langs->trans("Status").' ('.$langs->trans("Sell").') ';
-print $object->getLibStatut(2,0);
+print ' ' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ') ';
+print $object->getLibStatut(2, 0);
print ' ';
print "
\n";
@@ -590,47 +539,40 @@ if (! empty($mesg)) {
dol_htmloutput_mesg($mesg);
}
-
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
-if (! $action || $action == 'delete')
-{
- print "\n".''."\n";
-
- if ($user->rights->produit->creer || $user->rights->service->creer)
- {
- print '
';
+if (! $action || $action == 'delete') {
+ print "\n" . '
' . "\n";
+
+ if ($user->rights->produit->creer || $user->rights->service->creer) {
+ print '
';
}
-
+
print "\n
\n";
}
-
-
/*
* Edition du prix
*/
-if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->service->creer))
-{
- print_fiche_titre($langs->trans("NewPrice"),'','');
-
- if (empty($conf->global->PRODUIT_MULTIPRICES))
- {
- print '
id.'" method="POST">';
- print ' ';
+if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->service->creer)) {
+ print_fiche_titre($langs->trans("NewPrice"), '', '');
+
+ if (empty($conf->global->PRODUIT_MULTIPRICES)) {
+ print ' id . '" method="POST">';
+ print ' ';
print ' ';
- print ' ';
+ print ' ';
print '';
-
- // VAT
- print ''.$langs->trans("VATRate").' ';
- print $form->load_tva("tva_tx",$object->tva_tx,$mysoc,'',$object->id,$object->tva_npr);
- print ' ';
-
+
+ // VAT
+ print '' . $langs->trans("VATRate") . ' ';
+ print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr);
+ print ' ';
+
// Price base
print '';
print $langs->trans('PriceBase');
@@ -639,230 +581,200 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->
print $form->select_PriceBaseType($object->price_base_type, "price_base_type");
print ' ';
print ' ';
-
+
// Price
print '';
- $text=$langs->trans('SellingPrice');
- print $form->textwithpicto($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),1,1);
+ $text = $langs->trans('SellingPrice');
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
print ' ';
- if ($object->price_base_type == 'TTC')
- {
- print ' ';
- }
- else
- {
- print ' ';
+ if ($object->price_base_type == 'TTC') {
+ print ' ';
+ } else {
+ print ' ';
}
print ' ';
-
+
// Price minimum
- print '' ;
- $text=$langs->trans('MinPrice');
- print $form->textwithpicto($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),1,1);
- if ($object->price_base_type == 'TTC')
- {
- print ' ';
- }
- else
- {
- print ' ';
+ print '';
+ $text = $langs->trans('MinPrice');
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
+ if ($object->price_base_type == 'TTC') {
+ print ' ';
+ } else {
+ print ' ';
}
print ' ';
-
+
print '
';
-
- print ' ';
- print ' ';
-
+
+ print ' ';
+ print ' ';
+
print ' ';
- }
- else
- {
- for ($i=1; $i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
- {
- print '
id.'" method="POST">';
- print ' ';
+ } else {
+ for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) {
+ print ' id . '" method="POST">';
+ print ' ';
print ' ';
- print ' ';
+ print ' ';
print '';
-
- // VAT
- if ($i == 1)
- {
- print ''.$langs->trans("VATRate").' ';
- print $form->load_tva("tva_tx_".$i,$object->multiprices_tva_tx["$i"],$mysoc,'',$object->id);
- print ' ';
- }
- else
- { // We always use the vat rate of price level 1 (A vat rate does not depends on customer)
- print ' ';
- }
-
+
+ // VAT
+ if ($i == 1) {
+ print '' . $langs->trans("VATRate") . ' ';
+ print $form->load_tva("tva_tx_" . $i, $object->multiprices_tva_tx ["$i"], $mysoc, '', $object->id);
+ print ' ';
+ } else { // We always use the vat rate of price level 1 (A vat rate does not depends on customer)
+ print ' ';
+ }
+
// Selling price
print '';
- $text=$langs->trans('SellingPrice').' '.$i;
- print $form->textwithpicto($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),1,1);
+ $text = $langs->trans('SellingPrice') . ' ' . $i;
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
print ' ';
- if ($object->multiprices_base_type["$i"] == 'TTC')
- {
- print ' ';
+ if ($object->multiprices_base_type ["$i"] == 'TTC') {
+ print ' ';
+ } else {
+ print ' ';
}
- else
- {
- print ' ';
- }
- print $form->select_PriceBaseType($object->multiprices_base_type["$i"], "multiprices_base_type_".$i);
+ print $form->select_PriceBaseType($object->multiprices_base_type ["$i"], "multiprices_base_type_" . $i);
print ' ';
-
- // Min price
+
+ // Min price
print '';
- $text=$langs->trans('MinPrice').' '.$i;
- print $form->textwithpicto($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),1,1);
- if ($object->multiprices_base_type["$i"] == 'TTC')
- {
- print ' ';
- }
- else
- {
- print ' ';
+ $text = $langs->trans('MinPrice') . ' ' . $i;
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
+ if ($object->multiprices_base_type ["$i"] == 'TTC') {
+ print ' ';
+ } else {
+ print ' ';
}
print ' ';
-
- print ' ';
- print ' ';
+
+ print ' ';
+ print ' ';
print '
';
print ' ';
}
-
}
}
-
// Liste des evolutions du prix
$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.recuperableonly,";
-$sql.= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
-$sql.= " p.date_price as dp, u.rowid as user_id, u.login";
-$sql.= " FROM ".MAIN_DB_PREFIX."product_price as p,";
-$sql.= " ".MAIN_DB_PREFIX."user as u";
-$sql.= " WHERE fk_product = ".$object->id;
-$sql.= " AND p.entity IN (".getEntity('productprice', 1).")";
-$sql.= " AND p.fk_user_author = u.rowid";
-if (! empty($socid) && ! empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND p.price_level = ".$soc->price_level;
-$sql.= " ORDER BY p.date_price DESC, p.price_level ASC";
-//$sql .= $db->plimit();
+$sql .= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
+$sql .= " p.date_price as dp, u.rowid as user_id, u.login";
+$sql .= " FROM " . MAIN_DB_PREFIX . "product_price as p,";
+$sql .= " " . MAIN_DB_PREFIX . "user as u";
+$sql .= " WHERE fk_product = " . $object->id;
+$sql .= " AND p.entity IN (" . getEntity('productprice', 1) . ")";
+$sql .= " AND p.fk_user_author = u.rowid";
+if (! empty($socid) && ! empty($conf->global->PRODUIT_MULTIPRICES))
+ $sql .= " AND p.price_level = " . $soc->price_level;
+$sql .= " ORDER BY p.date_price DESC, p.price_level ASC";
+// $sql .= $db->plimit();
-dol_syslog("sql=".$sql);
+dol_syslog("sql=" . $sql);
$result = $db->query($sql);
-if ($result)
-{
+if ($result) {
$num = $db->num_rows($result);
-
- if (! $num)
- {
+
+ if (! $num) {
$db->free($result);
-
+
// Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre a niveau (pb vieilles versions)
$object->updatePrice($object->price, $object->price_base_type, $user, $newprice_min);
-
+
$result = $db->query($sql);
$num = $db->num_rows($result);
}
-
- if ($num > 0)
- {
+
+ if ($num > 0) {
print '
';
-
+
print '
';
-
+
print '';
- print ''.$langs->trans("AppliedPricesFrom").' ';
-
- if (! empty($conf->global->PRODUIT_MULTIPRICES))
- {
- print ''.$langs->trans("MultiPriceLevelsName").' ';
+ print '' . $langs->trans("AppliedPricesFrom") . ' ';
+
+ if (! empty($conf->global->PRODUIT_MULTIPRICES)) {
+ print '' . $langs->trans("MultiPriceLevelsName") . ' ';
}
- if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
- {
- print ''.$langs->trans("Type").' ';
+ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
+ print '' . $langs->trans("Type") . ' ';
}
-
- print ''.$langs->trans("PriceBase").' ';
- print ''.$langs->trans("VAT").' ';
- print ''.$langs->trans("HT").' ';
- print ''.$langs->trans("TTC").' ';
- print ''.$langs->trans("MinPrice").' '.$langs->trans("HT").' ';
- print ''.$langs->trans("MinPrice").' '.$langs->trans("TTC").' ';
- print ''.$langs->trans("ChangedBy").' ';
- if ($user->rights->produit->supprimer) print ' ';
+
+ print '' . $langs->trans("PriceBase") . ' ';
+ print '' . $langs->trans("VAT") . ' ';
+ print '' . $langs->trans("HT") . ' ';
+ print '' . $langs->trans("TTC") . ' ';
+ print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . ' ';
+ print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . ' ';
+ print '' . $langs->trans("ChangedBy") . ' ';
+ if ($user->rights->produit->supprimer)
+ print ' ';
print ' ';
-
- $var=True;
+
+ $var = True;
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$objp = $db->fetch_object($result);
- $var=!$var;
+ $var = ! $var;
print "";
// Date
- print "".dol_print_date($db->jdate($objp->dp),"dayhour")." ";
-
+ print "" . dol_print_date($db->jdate($objp->dp), "dayhour") . " ";
+
// Price level
- if (! empty($conf->global->PRODUIT_MULTIPRICES))
- {
- print ''.$objp->price_level." ";
+ if (! empty($conf->global->PRODUIT_MULTIPRICES)) {
+ print '' . $objp->price_level . " ";
}
// Price by quantity
- if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
- {
+ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
$type = ($objp->price_by_qty == 1) ? 'PriceByQuantity' : 'Standard';
- print ''.$langs->trans($type)." ";
+ print '' . $langs->trans($type) . " ";
}
-
- print ''.$langs->trans($objp->price_base_type)." ";
- print ''.vatrate($objp->tva_tx,true,$objp->recuperableonly)." ";
- print ''.price($objp->price)." ";
- print ''.price($objp->price_ttc)." ";
- print ''.price($objp->price_min).' ';
- print ''.price($objp->price_min_ttc).' ';
-
+
+ print '' . $langs->trans($objp->price_base_type) . " ";
+ print '' . vatrate($objp->tva_tx, true, $objp->recuperableonly) . " ";
+ print '' . price($objp->price) . " ";
+ print '' . price($objp->price_ttc) . " ";
+ print '' . price($objp->price_min) . ' ';
+ print '' . price($objp->price_min_ttc) . ' ';
+
// User
- print ''.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.' ';
-
+ print '' . img_object($langs->trans("ShowUser"), 'user') . ' ' . $objp->login . ' ';
+
// Action
- if ($user->rights->produit->supprimer)
- {
+ if ($user->rights->produit->supprimer) {
print '';
- if ($i > 0)
- {
- print 'id.'&lineid='.$objp->rowid.'">';
+ if ($i > 0) {
+ print ' id . '&lineid=' . $objp->rowid . '">';
print img_delete();
print ' ';
- }
- else print ' '; // Can not delete last price (it's current price)
+ } else
+ print ' '; // Can not delete last price (it's current price)
print ' ';
}
-
+
print " \n";
- $i++;
+ $i ++;
}
$db->free($result);
print "
";
print "
";
}
-}
-else
-{
+} else {
dol_print_error($db);
}
-if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
+if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
- $prodcustprice = new Productcustomerprice ( $db );
+ $prodcustprice = new Productcustomerprice($db);
- $sortfield = GETPOST ( "sortfield", 'alpha' );
- $sortorder = GETPOST ( "sortorder", 'alpha' );
- $page = GETPOST ( "page", 'int' );
+ $sortfield = GETPOST("sortfield", 'alpha');
+ $sortorder = GETPOST("sortorder", 'alpha');
+ $page = GETPOST("page", 'int');
if ($page == - 1) {
$page = 0;
}
@@ -875,12 +787,10 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
$sortfield = "soc.nom";
// Build filter to diplay only concerned lines
- $filter = array (
- 't.fk_product' => $object->id
- );
+ $filter = array('t.fk_product' => $object->id);
- $search_soc = GETPOST ( 'search_soc' );
- if (! empty ( $search_soc )) {
+ $search_soc = GETPOST('search_soc');
+ if (! empty($search_soc)) {
$filter ['soc.nom'] = $search_soc;
}
@@ -888,7 +798,7 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
// Create mode
- print_fiche_titre ( $langs->trans ( 'PriceByCustomer' ) );
+ print_fiche_titre($langs->trans('PriceByCustomer'));
print '
id . '" method="POST">';
print ' ';
@@ -896,52 +806,52 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print ' ';
print '';
print '';
- print '' . $langs->trans ( 'ThirdParty' ) . ' ';
+ print '' . $langs->trans('ThirdParty') . ' ';
print '';
- print $form->select_company ( '', 'socid', 's.rowid NOT IN (SELECT fk_soc FROM ' . MAIN_DB_PREFIX . 'product_customer_price)', 1 );
+ print $form->select_company('', 'socid', 's.rowid NOT IN (SELECT fk_soc FROM ' . MAIN_DB_PREFIX . 'product_customer_price)', 1);
print ' ';
print ' ';
// VAT
- print '' . $langs->trans ( "VATRate" ) . ' ';
- print $form->load_tva ( "tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr );
+ print ' ' . $langs->trans("VATRate") . ' ';
+ print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr);
print ' ';
// Price base
print '';
- print $langs->trans ( 'PriceBase' );
+ print $langs->trans('PriceBase');
print ' ';
print '';
- print $form->select_PriceBaseType ( $object->price_base_type, "price_base_type" );
+ print $form->select_PriceBaseType($object->price_base_type, "price_base_type");
print ' ';
print ' ';
// Price
print '';
- $text = $langs->trans ( 'SellingPrice' );
- print $form->textwithpicto ( $text, $langs->trans ( "PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT ), 1, 1 );
+ $text = $langs->trans('SellingPrice');
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
print ' ';
if ($object->price_base_type == 'TTC') {
- print ' ';
+ print ' ';
} else {
- print ' ';
+ print ' ';
}
print ' ';
// Price minimum
print '';
- $text = $langs->trans ( 'MinPrice' );
- print $form->textwithpicto ( $text, $langs->trans ( "PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT ), 1, 1 );
+ $text = $langs->trans('MinPrice');
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
if ($object->price_base_type == 'TTC') {
- print ' ';
+ print ' ';
} else {
- print ' ';
+ print ' ';
}
print ' ';
// Update all child soc
print '';
- print $langs->trans ( 'ForceUpdateChildPriceSoc' );
+ print $langs->trans('ForceUpdateChildPriceSoc');
print ' ';
print '';
print ' ';
@@ -950,19 +860,19 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print '
';
- print ' ';
- print ' ';
+ print ' ';
+ print ' ';
print ' ';
} elseif ($action == 'edit_customer_price') {
// Edit mode
- print_fiche_titre ( $langs->trans ( 'PriceByCustomer' ) );
+ print_fiche_titre($langs->trans('PriceByCustomer'));
- $result = $prodcustprice->fetch ( GETPOST ( 'lineid', 'int' ) );
+ $result = $prodcustprice->fetch(GETPOST('lineid', 'int'));
if ($result < 0) {
- setEventMessage ( $prodcustprice->error, 'errors' );
+ setEventMessage($prodcustprice->error, 'errors');
}
print '
id . '" method="POST">';
@@ -971,52 +881,52 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print ' ';
print '';
print '';
- print '' . $langs->trans ( 'ThirdParty' ) . ' ';
- $staticsoc = new Societe ( $db );
- $staticsoc->fetch ( $prodcustprice->fk_soc );
- print "" . $staticsoc->getNomUrl ( 1 ) . " ";
+ print '' . $langs->trans('ThirdParty') . ' ';
+ $staticsoc = new Societe($db);
+ $staticsoc->fetch($prodcustprice->fk_soc);
+ print "" . $staticsoc->getNomUrl(1) . " ";
print ' ';
// VAT
- print '' . $langs->trans ( "VATRate" ) . ' ';
- print $form->load_tva ( "tva_tx", $prodcustprice->tva_tx, $mysoc, '', $object->id, $prodcustprice->recuperableonly );
+ print ' ' . $langs->trans("VATRate") . ' ';
+ print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, '', $object->id, $prodcustprice->recuperableonly);
print ' ';
// Price base
print '';
- print $langs->trans ( 'PriceBase' );
+ print $langs->trans('PriceBase');
print ' ';
print '';
- print $form->select_PriceBaseType ( $prodcustprice->price_base_type, "price_base_type" );
+ print $form->select_PriceBaseType($prodcustprice->price_base_type, "price_base_type");
print ' ';
print ' ';
// Price
print '';
- $text = $langs->trans ( 'SellingPrice' );
- print $form->textwithpicto ( $text, $langs->trans ( "PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT ), 1, 1 );
+ $text = $langs->trans('SellingPrice');
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
print ' ';
if ($prodcustprice->price_base_type == 'TTC') {
- print ' ';
+ print ' ';
} else {
- print ' ';
+ print ' ';
}
print ' ';
// Price minimum
print '';
- $text = $langs->trans ( 'MinPrice' );
- print $form->textwithpicto ( $text, $langs->trans ( "PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT ), 1, 1 );
+ $text = $langs->trans('MinPrice');
+ print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
if ($prodcustprice->price_base_type == 'TTC') {
- print ' ';
+ print ' ';
} else {
- print ' ';
+ print ' ';
}
print ' ';
// Update all child soc
print '';
- print $langs->trans ( 'ForceUpdateChildPriceSoc' );
+ print $langs->trans('ForceUpdateChildPriceSoc');
print ' ';
print '';
print ' ';
@@ -1025,113 +935,103 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print '
';
- print ' ';
- print ' ';
+ print ' ';
+ print ' ';
print ' ';
- } elseif ($action=='showlog_customer_price') {
+ } elseif ($action == 'showlog_customer_price') {
-
- $filter = array (
- 't.fk_product' => $object->id,
- 't.fk_soc'=> GETPOST('socid','int')
- );
+ $filter = array('t.fk_product' => $object->id,'t.fk_soc' => GETPOST('socid', 'int'));
// Count total nb of records
$nbtotalofrecords = 0;
- if (empty ( $conf->global->MAIN_DISABLE_FULL_SCANLIST )) {
- $nbtotalofrecords = $prodcustprice->fetch_all_log ( $sortorder, $sortfield, $conf->liste_limit, $offset, $filter );
+ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ $nbtotalofrecords = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
}
- $result = $prodcustprice->fetch_all_log ( $sortorder, $sortfield, $conf->liste_limit, $offset, $filter );
+ $result = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
if ($result < 0) {
- setEventMessage ( $prodcustprice->error, 'errors' );
+ setEventMessage($prodcustprice->error, 'errors');
}
- $option = '&socid=' . GETPOST('socid','int') . '&id=' . $object->id;
+ $option = '&socid=' . GETPOST('socid', 'int') . '&id=' . $object->id;
- print_barre_liste ( $langs->trans ( 'PriceByCustomerLog' ), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count ( $prodcustprice->lines ), $nbtotalofrecords );
+ print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords);
- if (count ( $prodcustprice->lines ) > 0) {
-
+ if (count($prodcustprice->lines) > 0) {
+
print '
id . '" method="POST">';
print ' ';
-
+
print '';
-
+
print '';
- print '' . $langs->trans ( "ThirdParty" ) . ' ';
- print '' . $langs->trans ( "AppliedPricesFrom" ) . ' ';
- print '' . $langs->trans ( "PriceBase" ) . ' ';
- print '' . $langs->trans ( "VAT" ) . ' ';
- print '' . $langs->trans ( "HT" ) . ' ';
- print '' . $langs->trans ( "TTC" ) . ' ';
- print '' . $langs->trans ( "MinPrice" ) . ' ' . $langs->trans ( "HT" ) . ' ';
- print '' . $langs->trans ( "MinPrice" ) . ' ' . $langs->trans ( "TTC" ) . ' ';
- print '' . $langs->trans ( "ChangedBy" ) . ' ';
+ print '' . $langs->trans("ThirdParty") . ' ';
+ print '' . $langs->trans("AppliedPricesFrom") . ' ';
+ print '' . $langs->trans("PriceBase") . ' ';
+ print '' . $langs->trans("VAT") . ' ';
+ print '' . $langs->trans("HT") . ' ';
+ print '' . $langs->trans("TTC") . ' ';
+ print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . ' ';
+ print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . ' ';
+ print '' . $langs->trans("ChangedBy") . ' ';
print ' ';
print ' ';
-
+
$var = True;
+
+ foreach ($prodcustprice->lines as $line) {
- foreach ( $prodcustprice->lines as $line ) {
-
print "";
// Date
- $staticsoc = new Societe ( $db );
- $staticsoc->fetch ( $line->fk_soc );
-
- print "" . $staticsoc->getNomUrl ( 1 ) . " ";
- print "" . dol_print_date ( $line->datec, "dayhour" ) . " ";
-
- print '' . $langs->trans ( $line->price_base_type ) . " ";
- print '' . vatrate ( $line->tva_tx, true, $line->recuperableonly ) . " ";
- print '' . price ( $line->price ) . " ";
- print '' . price ( $line->price_ttc ) . " ";
- print '' . price ( $line->price_min ) . ' ';
- print '' . price ( $line->price_min_ttc ) . ' ';
-
+ $staticsoc = new Societe($db);
+ $staticsoc->fetch($line->fk_soc);
+
+ print "" . $staticsoc->getNomUrl(1) . " ";
+ print "" . dol_print_date($line->datec, "dayhour") . " ";
+
+ print '' . $langs->trans($line->price_base_type) . " ";
+ print '' . vatrate($line->tva_tx, true, $line->recuperableonly) . " ";
+ print '' . price($line->price) . " ";
+ print '' . price($line->price_ttc) . " ";
+ print '' . price($line->price_min) . ' ';
+ print '' . price($line->price_min_ttc) . ' ';
+
// User
- $userstatic=new User($db);
+ $userstatic = new User($db);
$userstatic->fetch($line->fk_user);
print '';
print $userstatic->getLoginUrl(1);
print ' ';
-
-
-
- }
- print "
";
- } else {
- print $langs->trans ( 'None' );
-
-
+ }
+ print "
";
+ } else {
+ print $langs->trans('None');
}
print "\n" . '' . "\n";
- print '
';
+ print '
';
print "\n
\n";
-
} else {
// View mode
// Count total nb of records
$nbtotalofrecords = 0;
- if (empty ( $conf->global->MAIN_DISABLE_FULL_SCANLIST )) {
- $nbtotalofrecords = $prodcustprice->fetch_all ( '', '', 0, 0, $filter );
+ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ $nbtotalofrecords = $prodcustprice->fetch_all('', '', 0, 0, $filter);
}
- $result = $prodcustprice->fetch_all ( $sortorder, $sortfield, $conf->liste_limit, $offset, $filter );
+ $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
if ($result < 0) {
- setEventMessage ( $prodcustprice->error, 'errors' );
+ setEventMessage($prodcustprice->error, 'errors');
}
$option = '&search_soc=' . $search_soc . '&id=' . $object->id;
- print_barre_liste ( $langs->trans ( 'PriceByCustomer' ), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count ( $prodcustprice->lines ), $nbtotalofrecords );
+ print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords);
- if (count ( $prodcustprice->lines ) > 0) {
+ if (count($prodcustprice->lines) > 0) {
print 'id . '" method="POST">';
print ' ';
@@ -1139,15 +1039,15 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print '';
print '';
- print '' . $langs->trans ( "ThirdParty" ) . ' ';
- print '' . $langs->trans ( "AppliedPricesFrom" ) . ' ';
- print '' . $langs->trans ( "PriceBase" ) . ' ';
- print '' . $langs->trans ( "VAT" ) . ' ';
- print '' . $langs->trans ( "HT" ) . ' ';
- print '' . $langs->trans ( "TTC" ) . ' ';
- print '' . $langs->trans ( "MinPrice" ) . ' ' . $langs->trans ( "HT" ) . ' ';
- print '' . $langs->trans ( "MinPrice" ) . ' ' . $langs->trans ( "TTC" ) . ' ';
- print '' . $langs->trans ( "ChangedBy" ) . ' ';
+ print '' . $langs->trans("ThirdParty") . ' ';
+ print '' . $langs->trans("AppliedPricesFrom") . ' ';
+ print '' . $langs->trans("PriceBase") . ' ';
+ print '' . $langs->trans("VAT") . ' ';
+ print '' . $langs->trans("HT") . ' ';
+ print '' . $langs->trans("TTC") . ' ';
+ print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . ' ';
+ print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . ' ';
+ print '' . $langs->trans("ChangedBy") . ' ';
print ' ';
print ' ';
@@ -1156,49 +1056,48 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print ' ';
// Print the search button
print '';
- print ' ';
+ print ' ';
print ' ';
print '';
$var = True;
- foreach ( $prodcustprice->lines as $line ) {
+ foreach ($prodcustprice->lines as $line) {
print "";
// Date
- $staticsoc = new Societe ( $db );
- $staticsoc->fetch ( $line->fk_soc );
+ $staticsoc = new Societe($db);
+ $staticsoc->fetch($line->fk_soc);
- print "" . $staticsoc->getNomUrl ( 1 ) . " ";
- print "" . dol_print_date ( $line->datec, "dayhour" ) . " ";
+ print "" . $staticsoc->getNomUrl(1) . " ";
+ print "" . dol_print_date($line->datec, "dayhour") . " ";
- print '' . $langs->trans ( $line->price_base_type ) . " ";
- print '' . vatrate ( $line->tva_tx, true, $line->recuperableonly ) . " ";
- print '' . price ( $line->price ) . " ";
- print '' . price ( $line->price_ttc ) . " ";
- print '' . price ( $line->price_min ) . ' ';
- print '' . price ( $line->price_min_ttc ) . ' ';
+ print '' . $langs->trans($line->price_base_type) . " ";
+ print '' . vatrate($line->tva_tx, true, $line->recuperableonly) . " ";
+ print '' . price($line->price) . " ";
+ print '' . price($line->price_ttc) . " ";
+ print '' . price($line->price_min) . ' ';
+ print '' . price($line->price_min_ttc) . ' ';
// User
- $userstatic=new User($db);
+ $userstatic = new User($db);
$userstatic->fetch($line->fk_user);
print '';
print $userstatic->getLoginUrl(1);
print ' ';
-
// Todo Edit or delete button
// Action
if ($user->rights->produit->supprimer || $user->rights->service->supprimer) {
print '';
print 'id . '&lineid=' . $line->id . '">';
- print img_delete ();
+ print img_delete();
print ' ';
print 'id . '&lineid=' . $line->id . '">';
- print img_edit ();
+ print img_edit();
print ' ';
print 'id . '&socid=' . $line->fk_soc . '">';
- print img_info ();
+ print img_info();
print ' ';
print ' ';
}
@@ -1209,7 +1108,7 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print "";
} else {
- print $langs->trans ( 'None' );
+ print $langs->trans('None');
}
/* ************************************************************************** */
@@ -1221,13 +1120,12 @@ if (! empty ( $conf->global->PRODUIT_CUSTOMER_PRICES )) {
print "\n" . '' . "\n";
if ($user->rights->produit->creer || $user->rights->service->creer) {
- print '
';
+ print '
';
}
print "\n
\n";
}
}
-
llxFooter();
$db->close();