*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -147,7 +147,7 @@ $tabsql[14]= "SELECT e.rowid as rowid, e.code as code, e.libelle, e.price, e.org
$tabsql[15]= "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format";
$tabsql[16]= "SELECT code, label as libelle, active FROM ".MAIN_DB_PREFIX."c_prospectlevel";
$tabsql[17]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_type_fees";
-$tabsql[18]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_shipment_mode";
+$tabsql[18]= "SELECT rowid as rowid, code, libelle, tracking, active FROM ".MAIN_DB_PREFIX."c_shipment_mode";
$tabsql[19]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_effectif";
$tabsql[20]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_input_method";
$tabsql[21]= "SELECT c.rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_availability AS c";
@@ -203,7 +203,7 @@ $tabfield[14]= "code,libelle,price,organization,country_id,country";
$tabfield[15]= "code,libelle,width,height,unit";
$tabfield[16]= "code,libelle";
$tabfield[17]= "code,libelle";
-$tabfield[18]= "code,libelle";
+$tabfield[18]= "code,libelle,tracking";
$tabfield[19]= "code,libelle";
$tabfield[20]= "code,libelle";
$tabfield[21]= "code,label";
@@ -231,7 +231,7 @@ $tabfieldvalue[14]= "code,libelle,price,organization,country";
$tabfieldvalue[15]= "code,libelle,width,height,unit";
$tabfieldvalue[16]= "code,libelle";
$tabfieldvalue[17]= "code,libelle";
-$tabfieldvalue[18]= "code,libelle";
+$tabfieldvalue[18]= "code,libelle,tracking";
$tabfieldvalue[19]= "code,libelle";
$tabfieldvalue[20]= "code,libelle";
$tabfieldvalue[21]= "code,label";
@@ -259,7 +259,7 @@ $tabfieldinsert[14]= "code,libelle,price,organization,fk_pays";
$tabfieldinsert[15]= "code,label,width,height,unit";
$tabfieldinsert[16]= "code,label";
$tabfieldinsert[17]= "code,libelle";
-$tabfieldinsert[18]= "code,libelle";
+$tabfieldinsert[18]= "code,libelle,tracking";
$tabfieldinsert[19]= "code,libelle";
$tabfieldinsert[20]= "code,libelle";
$tabfieldinsert[21]= "code,label";
@@ -391,7 +391,7 @@ if ($id == 11)
// Define localtax_typeList (used for dictionnary "c_tva")
$localtax_typeList = array();
-if (GETPOST("id") == 10)
+if ($id == 10)
{
$localtax_typeList = array(
"0" => $langs->trans("No"),
@@ -441,22 +441,32 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode';
- $msg.=$langs->trans("ErrorFieldRequired",$langs->transnoentities($fieldnamekey)).' ';
+ $msg.=$langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)).' ';
}
}
// Other checks
if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
$ok=0;
- $msg.="Value 'system' and 'systemauto' for type is reserved. You can use 'user' as value to add your own record. ";
+ $msg.= $langs->transnoentities('ErrorReservedTypeSystemSystemAuto').' ';
}
- if (isset($_POST["code"]) && $_POST["code"]=='0') {
- $ok=0;
- $msg.="Code can't contains value 0 ";
+ if (isset($_POST["code"]))
+ {
+ if ($_POST["code"]=='0')
+ {
+ $ok=0;
+ $msg.= $langs->transnoentities('ErrorCodeCantContainZero').' ';
+ }
+ if (!is_numeric($_POST['code']))
+ {
+ $ok = 0;
+ $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).' ';
+ }
}
if (isset($_POST["country"]) && $_POST["country"]=='0') {
$ok=0;
- $msg.=$langs->trans("ErrorFieldRequired",$langs->trans("Country")).' ';
+ $msg.=$langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")).' ';
}
+
// Clean some parameters
if (isset($_POST["localtax1"]) && empty($_POST["localtax1"])) $_POST["localtax1"]='0'; // If empty, we force to 0
if (isset($_POST["localtax2"]) && empty($_POST["localtax2"])) $_POST["localtax2"]='0'; // If empty, we force to 0
@@ -518,7 +528,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
else
{
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
- $msg=$langs->trans("ErrorRecordAlreadyExists").' ';
+ $msg=$langs->transnoentities("ErrorRecordAlreadyExists").' ';
}
else {
dol_print_error($db);
@@ -588,7 +598,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete
{
if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
{
- $msg=''.$langs->trans("ErrorRecordIsUsedByChild").'
';
+ $msg=''.$langs->transnoentities("ErrorRecordIsUsedByChild").'
';
}
else
{
@@ -994,6 +1004,7 @@ if ($id)
$valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]);
}
else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') {
+ $langs->load('agenda');
$key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
$valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]);
}
@@ -1084,15 +1095,23 @@ if ($id)
}
// Est-ce une entree du dictionnaire qui peut etre desactivee ?
- $iserasable=1; // Oui par defaut
- if (isset($obj->code) && ($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) $iserasable=0;
- if (isset($obj->code) && $obj->code == 'RECEP') $iserasable=0;
- if (isset($obj->code) && $obj->code == 'EF0') $iserasable=0;
+ // True by default
+ $iserasable=1;
+
+ if (isset($obj->code))
+ {
+ if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) $iserasable = 0;
+ else if ($obj->code == 'RECEP') $iserasable = 0;
+ else if ($obj->code == 'EF0') $iserasable = 0;
+ }
+
if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) $iserasable=0;
+ $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?$obj->code:'').'&id='.$id.'&';
+
// Active
print '';
- if ($iserasable) print 'rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?$obj->code:'').'&id='.$id.'&action='.$acts[$obj->active].'">'.$actl[$obj->active].' ';
+ if ($iserasable) print ''.$actl[$obj->active].' ';
else
{
if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
@@ -1101,11 +1120,11 @@ if ($id)
print " ";
// Modify link
- if ($iserasable) print 'rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?$obj->code:'').'&id='.$id.'&action=edit#'.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'">'.img_edit().' ';
+ if ($iserasable) print ''.img_edit().' ';
else print ' ';
// Delete link
- if ($iserasable) print 'rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?$obj->code:'').'&id='.$id.'&action=delete">'.img_delete().' ';
+ if ($iserasable) print ''.img_delete().' ';
else print ' ';
print "\n";
@@ -1153,7 +1172,7 @@ else
$var=!$var;
$value=$tabname[$i];
- print '';
+ print ' ';
if (! empty($tabcond[$i]))
{
print ''.$langs->trans($tablib[$i]).' ';
@@ -1299,6 +1318,7 @@ function fieldList($fieldlist,$obj='',$tabname='')
print ' ';
$size='';
if ($fieldlist[$field]=='libelle') $size='size="32" ';
+ if ($fieldlist[$field]=='tracking') $size='size="92" ';
if ($fieldlist[$field]=='accountancy_code') $size='size="15" ';
if ($fieldlist[$field]=='accountancy_code_sell') $size='size="15" ';
if ($fieldlist[$field]=='accountancy_code_buy') $size='size="15" ';
diff --git a/htdocs/admin/expedition.php b/htdocs/admin/expedition.php
index 34535b1d321..28e5b912de2 100644
--- a/htdocs/admin/expedition.php
+++ b/htdocs/admin/expedition.php
@@ -201,10 +201,6 @@ $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
$head[$h][1] = $langs->trans("Setup");
$h++;
-$head[$h][0] = DOL_URL_ROOT."/admin/carrier.php";
-$head[$h][1] = $langs->trans("Carriers");
-$h++;
-
$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
$head[$h][1] = $langs->trans("Sending");
$hselected=$h;
diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php
index 49cbeee9026..677e2b3773b 100644
--- a/htdocs/admin/livraison.php
+++ b/htdocs/admin/livraison.php
@@ -189,10 +189,6 @@ $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
$head[$h][1] = $langs->trans("Setup");
$h++;
-$head[$h][0] = DOL_URL_ROOT."/admin/carrier.php";
-$head[$h][1] = $langs->trans("Carriers");
-$h++;
-
if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
{
$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php
index 569200f35e4..f7bd7ad95d7 100644
--- a/htdocs/admin/menus/edit.php
+++ b/htdocs/admin/menus/edit.php
@@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
$langs->load("admin");
+$langs->load('other');
if (! $user->admin) accessforbidden();
diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php
index 4440d632b2e..acdf756eb86 100644
--- a/htdocs/admin/modules.php
+++ b/htdocs/admin/modules.php
@@ -194,7 +194,7 @@ asort($orders);
$nbofactivatedmodules=count($conf->modules);
$moreinfo=$langs->trans("TotalNumberOfActivatedModules",($nbofactivatedmodules-1));
-
+if ($nbofactivatedmodules <= 1) $moreinfo .= ' '.img_warning($langs->trans("YouMustEnableOneModule"));
print load_fiche_titre($langs->trans("ModulesSetup"),$moreinfo,'setup');
// Start to show page
@@ -206,7 +206,7 @@ if ($mode==='functional') print $langs->trans("ModulesJobDesc")." \n";
if ($mode==='marketplace') print $langs->trans("ModulesMarketPlaceDesc")." \n";
if ($mode==='expdev') print $langs->trans("ModuleFamilyExperimental")." \n";
-if ($nbofactivatedmodules <= 1) print ' '.img_warning($langs->trans("YouMustEnableOneModule"));
+
//print ' '."\n";
diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php
index bbdbf3276db..0390efcdda4 100644
--- a/htdocs/admin/stock.php
+++ b/htdocs/admin/stock.php
@@ -4,6 +4,7 @@
* Copyright (C) 2005-2009 Regis Houssin
* Copyright (C) 2012 Juanjo Menent
* Copyright (C) 2013 Philippe Grand
+ * Copyright (C) 2013 Florian Henry
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -67,6 +68,7 @@ if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL'
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity);
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity);
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity);
+ $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_DELETE_INVOICE", '','chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity);
@@ -239,6 +241,19 @@ if (! empty($conf->fournisseur->enabled))
print ' ';
print "\n \n \n";
}
+if (! empty($conf->facture->enabled))
+{
+ $var=!$var;
+ print "";
+ print ''.$langs->trans("ReStockOnDeleteInvoice").' ';
+ print '';
+ print "\n \n \n";
+}
print '';
diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php
index ddc7079c786..ec2a2b49d63 100644
--- a/htdocs/categories/categorie.php
+++ b/htdocs/categories/categorie.php
@@ -99,7 +99,7 @@ $error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->e
if (empty($reshook))
{
- //Suppression d'un objet d'une categorie
+ // Remove element from category
if ($removecat > 0)
{
if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer))
@@ -113,17 +113,20 @@ if (empty($reshook))
{
$object = new Societe($db);
$result = $object->fetch($objectid);
+ $elementtype = 'fournisseur';
}
if ($type==2 && $user->rights->societe->creer)
{
$object = new Societe($db);
$result = $object->fetch($objectid);
+ $elementtype = 'societe';
}
if ($type == 3 && $user->rights->adherent->creer)
{
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
$object = new Adherent($db);
$result = $object->fetch($objectid);
+ $elementtype = 'member';
}
$cat = new Categorie($db);
$result=$cat->fetch($removecat);
@@ -507,7 +510,7 @@ function formCategory($db,$object,$typeid,$socid=0)
//print $c->getNomUrl(1);
print img_object('','category').' '.$way."";
- // Lien supprimer
+ // Link to delete from category
print '';
$permission=0;
if ($typeid == 0) $permission=($user->rights->produit->creer || $user->rights->service->creer);
diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index 96c111f2dc0..377c06fd8d8 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -420,6 +420,7 @@ class Categorie
$sql .= " WHERE fk_categorie = ".$this->id;
$sql .= " AND fk_".($type=='fournisseur'?'societe':$type)." = ".$obj->id;
+ dol_syslog(get_class($this).'::del_type sql='.$sql);
if ($this->db->query($sql))
{
return 1;
diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php
index f174f5f4a60..57cffd387de 100644
--- a/htdocs/categories/viewcat.php
+++ b/htdocs/categories/viewcat.php
@@ -36,6 +36,7 @@ $ref=GETPOST('ref');
$type=GETPOST('type');
$action=GETPOST('action');
$confirm=GETPOST('confirm');
+$removeelem = GETPOST('removeelem','int');
if ($id == "")
{
@@ -61,6 +62,40 @@ $type=$object->type;
* Actions
*/
+// Remove element from category
+if ($id > 0 && $removeelem > 0)
+{
+ if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer))
+ {
+ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+ $tmpobject = new Product($db);
+ $result = $tmpobject->fetch($removeelem);
+ $elementtype = 'product';
+ }
+ if ($type==1 && $user->rights->societe->creer)
+ {
+ $tmpobject = new Societe($db);
+ $result = $tmpobject->fetch($removeelem);
+ $elementtype = 'fournisseur';
+ }
+ if ($type==2 && $user->rights->societe->creer)
+ {
+ $tmpobject = new Societe($db);
+ $result = $tmpobject->fetch($removeelem);
+ $elementtype = 'societe';
+ }
+ if ($type == 3 && $user->rights->adherent->creer)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
+ $tmpobject = new Adherent($db);
+ $result = $tmpobject->fetch($removeelem);
+ $elementtype = 'member';
+ }
+
+ $result=$object->del_type($tmpobject,$elementtype);
+ if ($result < 0) dol_print_error('',$object->error);
+}
+
if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confirm == 'yes')
{
if ($object->delete($user) >= 0)
@@ -214,7 +249,7 @@ if ($object->type == 0)
{
print " ";
print "\n";
- print ''.$langs->trans("ProductsAndServices")." \n";
+ print ''.$langs->trans("ProductsAndServices")." \n";
if (count($prods) > 0)
{
@@ -224,10 +259,24 @@ if ($object->type == 0)
$var=!$var;
print "\t\n";
print '';
- if ($prod->type == 1) print img_object($langs->trans("ShowService"),"service");
- else print img_object($langs->trans("ShowProduct"),"product");
- print " ".$prod->ref." \n";
+ print $prod->getNomUrl(1,'category');
+ print "\n";
print ''.$prod->libelle." \n";
+ // Link to delete from category
+ print '';
+ $typeid=$object->type;
+ $permission=0;
+ if ($typeid == 0) $permission=($user->rights->produit->creer || $user->rights->service->creer);
+ if ($typeid == 1) $permission=$user->rights->societe->creer;
+ if ($typeid == 2) $permission=$user->rights->societe->creer;
+ if ($typeid == 3) $permission=$user->rights->adherent->creer;
+ if ($permission)
+ {
+ print "id."&type=".$typeid."&removeelem=".$prod->id."'>";
+ print img_delete($langs->trans("DeleteFromCat")).' ';
+ print $langs->trans("DeleteFromCat")." ";
+ }
+ print ' ';
print " \n";
}
}
@@ -249,8 +298,8 @@ if ($object->type == 1)
else
{
print " ";
- print "\n";
- print "".$langs->trans("Suppliers")." \n";
+ print ''."\n";
+ print ''.$langs->trans("Suppliers")." \n";
if (count($socs) > 0)
{
@@ -261,9 +310,24 @@ if ($object->type == 1)
print "\t\n";
print '';
- print $soc->getNomUrl(1);
+ print $soc->getNomUrl(1,'category_supplier');
print " \n";
-
+ // Link to delete from category
+ print '';
+ $typeid=$object->type;
+ $permission=0;
+ if ($typeid == 0) $permission=($user->rights->produit->creer || $user->rights->service->creer);
+ if ($typeid == 1) $permission=$user->rights->societe->creer;
+ if ($typeid == 2) $permission=$user->rights->societe->creer;
+ if ($typeid == 3) $permission=$user->rights->adherent->creer;
+ if ($permission)
+ {
+ print "id."&type=".$typeid."&removeelem=".$soc->id."'>";
+ print img_delete($langs->trans("DeleteFromCat")).' ';
+ print $langs->trans("DeleteFromCat")." ";
+ }
+ print ' ';
+
print " \n";
}
}
@@ -285,8 +349,8 @@ if($object->type == 2)
else
{
print " ";
- print "\n";
- print "".$langs->trans("Customers")." \n";
+ print ''."\n";
+ print ''.$langs->trans("Customers")." \n";
if (count($socs) > 0)
{
@@ -298,9 +362,23 @@ if($object->type == 2)
$var=!$var;
print "\t\n";
print '';
- print $soc->getNomUrl(1);
+ print $soc->getNomUrl(1,'category');
print " \n";
-
+ // Link to delete from category
+ print '';
+ $typeid=$object->type;
+ $permission=0;
+ if ($typeid == 0) $permission=($user->rights->produit->creer || $user->rights->service->creer);
+ if ($typeid == 1) $permission=$user->rights->societe->creer;
+ if ($typeid == 2) $permission=$user->rights->societe->creer;
+ if ($typeid == 3) $permission=$user->rights->adherent->creer;
+ if ($permission)
+ {
+ print "id."&type=".$typeid."&removeelem=".$soc->id."'>";
+ print img_delete($langs->trans("DeleteFromCat")).' ';
+ print $langs->trans("DeleteFromCat")." ";
+ }
+ print ' ';
print " \n";
}
}
@@ -326,7 +404,7 @@ if ($object->type == 3)
{
print " ";
print "\n";
- print ''.$langs->trans("Member")." \n";
+ print ''.$langs->trans("Member")." \n";
if (count($prods) > 0)
{
@@ -336,10 +414,25 @@ if ($object->type == 3)
$var=!$var;
print "\t\n";
print '';
- print $member->getNomUrl(1);
+ $member->ref=$member->login;
+ print $member->getNomUrl(1,0,'category');
print " \n";
print ''.$member->lastname." \n";
print ''.$member->firstname." \n";
+ // Link to delete from category
+ print '';
+ $typeid=$object->type;
+ $permission=0;
+ if ($typeid == 0) $permission=($user->rights->produit->creer || $user->rights->service->creer);
+ if ($typeid == 1) $permission=$user->rights->societe->creer;
+ if ($typeid == 2) $permission=$user->rights->societe->creer;
+ if ($typeid == 3) $permission=$user->rights->adherent->creer;
+ if ($permission)
+ {
+ print "id."&type=".$typeid."&removeelem=".$member->id."'>";
+ print img_delete($langs->trans("DeleteFromCat")).' ';
+ print $langs->trans("DeleteFromCat")." ";
+ }
print " \n";
}
}
diff --git a/htdocs/comm/action/class/cactioncomm.class.php b/htdocs/comm/action/class/cactioncomm.class.php
index c686db153c4..e9fe439e75c 100644
--- a/htdocs/comm/action/class/cactioncomm.class.php
+++ b/htdocs/comm/action/class/cactioncomm.class.php
@@ -132,7 +132,7 @@ class CActionComm
$qualified=1;
// $obj->type can be system, systemauto, module, moduleauto, xxx, xxxauto
- if ($qualified && $onlyautoornot && preg_match('/^system/',$obj->type) && ! preg_match('/^AC_OTH/',$obj->code)) $qualified=0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTHER)
+ if ($qualified && $onlyautoornot && preg_match('/^system/',$obj->type) && ! preg_match('/^AC_OTH/',$obj->code)) $qualified=0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
if ($qualified && $obj->module)
{
diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php
index 37c5aaba693..4b4917715b5 100644
--- a/htdocs/comm/action/fiche.php
+++ b/htdocs/comm/action/fiche.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2004-2012 Laurent Destailleur
+ * Copyright (C) 2004-2013 Laurent Destailleur
* Copyright (C) 2005 Simon TOSSER
* Copyright (C) 2005-2012 Regis Houssin
* Copyright (C) 2010 Juanjo Menent
@@ -592,7 +592,7 @@ if ($action == 'create')
// Description
print ''.$langs->trans("Description").' ';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- $doleditor=new DolEditor('note',(GETPOST('note')?GETPOST('note'):$actioncomm->note),'',280,'dolibarr_notes','In',true,true,$conf->fckeditor->enabled,ROWS_7,90);
+ $doleditor=new DolEditor('note',(GETPOST('note')?GETPOST('note'):$actioncomm->note),'',240,'dolibarr_notes','In',true,true,$conf->fckeditor->enabled,ROWS_7,90);
$doleditor->Create();
print ' ';
@@ -663,7 +663,6 @@ if ($id > 0)
*/
$head=actions_prepare_head($act);
- dol_fiche_head($head, 'card', $langs->trans("Action"),0,'action');
$now=dol_now();
$delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
@@ -711,6 +710,8 @@ if ($id > 0)
print ' ';
if ($backtopage) print ' ';
+ dol_fiche_head($head, 'card', $langs->trans("Action"),0,'action');
+
print '';
// Ref
@@ -836,7 +837,9 @@ if ($id > 0)
print '
';
- print ' ';
+ dol_fiche_end();
+
+ print ' ';
print ' ';
print ' ';
@@ -844,6 +847,8 @@ if ($id > 0)
}
else
{
+ dol_fiche_head($head, 'card', $langs->trans("Action"),0,'action');
+
// Affichage fiche action en mode visu
print '';
@@ -1021,14 +1026,13 @@ if ($id > 0)
}
print '
';
}
- }
- print "\n";
+ dol_fiche_end();
+ }
/*
* Barre d'actions
- *
*/
print '';
diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php
index 49a84a28d22..813c2578374 100644
--- a/htdocs/comm/action/index.php
+++ b/htdocs/comm/action/index.php
@@ -1,7 +1,7 @@
* Copyright (C) 2003 Eric Seigne
- * Copyright (C) 2004-2012 Laurent Destailleur
+ * Copyright (C) 2004-2013 Laurent Destailleur
* Copyright (C) 2005-2012 Regis Houssin
* Copyright (C) 2011 Juanjo Menent
*
@@ -72,11 +72,11 @@ $year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
$month=GETPOST("month","int")?GETPOST("month","int"):date("m");
$week=GETPOST("week","int")?GETPOST("week","int"):date("W");
$day=GETPOST("day","int")?GETPOST("day","int"):0;
-$actioncode=GETPOST("actioncode","alpha",3);
$pid=GETPOST("projectid","int",3);
$status=GETPOST("status");
$type=GETPOST("type");
$maxprint=(isset($_GET["maxprint"])?GETPOST("maxprint"):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
+$actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=="0"?'':(empty($conf->global->AGENDA_USE_EVENT_TYPE)?'AC_OTH':''));
if (GETPOST('viewcal')) {
$action='show_month'; $day='';
@@ -271,7 +271,7 @@ $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
$head = calendars_prepare_head('');
dol_fiche_head($head, 'card', $langs->trans('Events'), 0, $picto);
-print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,$listofextcals);
+print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,$listofextcals,$actioncode);
dol_fiche_end();
$link='';
diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php
index b603792b957..9e7a7a959bb 100644
--- a/htdocs/comm/action/listactions.php
+++ b/htdocs/comm/action/listactions.php
@@ -238,7 +238,7 @@ if ($resql)
$i = 0;
print '';
print '';
- print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"acode",$param,"","",$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"a.label",$param,"","",$sortfield,$sortorder);
//print_liste_field_titre($langs->trans("Title"),$_SERVER["PHP_SELF"],"a.label",$param,"","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"a.datep",$param,'','align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateEnd"),$_SERVER["PHP_SELF"],"a.datep2",$param,'','align="center"',$sortfield,$sortorder);
diff --git a/htdocs/comm/action/rapport/index.php b/htdocs/comm/action/rapport/index.php
index 33a30e9c6b6..fa100e532f3 100644
--- a/htdocs/comm/action/rapport/index.php
+++ b/htdocs/comm/action/rapport/index.php
@@ -132,7 +132,7 @@ if ($resql)
if (file_exists($file))
{
- print ''.img_pdf().' ';
+ print ''.img_pdf().' ';
print ''.dol_print_date(dol_filemtime($file),'dayhour').' ';
print ''.dol_print_size(dol_filesize($file)).' ';
}
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index c178c37078b..2a7c92dce56 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1534,7 +1534,7 @@ else
require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
$notify=new Notify($db);
$text.=' ';
- $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$object->socid);
+ $text.=$notify->confirmMessage('PROPAL_VALIDATE',$object->socid);
}
if (! $error) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1);
@@ -2171,7 +2171,7 @@ else
//print '
';
- print ' ';
+ print '';
}
diff --git a/htdocs/comm/propal/apercu.php b/htdocs/comm/propal/apercu.php
index fa01f818b16..8972baaac88 100644
--- a/htdocs/comm/propal/apercu.php
+++ b/htdocs/comm/propal/apercu.php
@@ -142,7 +142,7 @@ if ($id > 0 || ! empty($ref))
print "".$langs->trans("Propal")." PDF ";
- print ''.$object->ref.'.pdf ';
+ print ''.$object->ref.'.pdf ';
print ''.dol_print_size(dol_filesize($file)).' ';
print ''.dol_print_date(dol_filemtime($file),'dayhour').' ';
diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php
index 4063802ffa4..1d4d5b82c24 100644
--- a/htdocs/comm/propal/list.php
+++ b/htdocs/comm/propal/list.php
@@ -3,7 +3,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur
* Copyright (C) 2004 Eric Seigne
* Copyright (C) 2005 Marc Barilley / Ocebo
- * Copyright (C) 2005-2012 Regis Houssin
+ * Copyright (C) 2005-2013 Regis Houssin
* Copyright (C) 2006 Andre Cianfarani
* Copyright (C) 2010-2011 Juanjo Menent
* Copyright (C) 2010-2011 Philippe Grand
@@ -165,7 +165,7 @@ if ($search_societe)
}
if ($search_montant_ht)
{
- $sql.= " AND p.total_ht='".$db->escape(trim($search_montant_ht))."'";
+ $sql.= " AND p.total_ht='".$db->escape(price2num(trim($search_montant_ht)))."'";
}
if ($sall) $sql.= " AND (s.nom LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%' OR pd.description LIKE '%".$db->escape($sall)."%')";
if ($socid) $sql.= ' AND s.rowid = '.$socid;
diff --git a/htdocs/commande/apercu.php b/htdocs/commande/apercu.php
index 03957361ae2..f92a309a53c 100644
--- a/htdocs/commande/apercu.php
+++ b/htdocs/commande/apercu.php
@@ -128,7 +128,7 @@ if ($id > 0 || ! empty($ref))
print "".$langs->trans("Order")." PDF ";
- print ''.$object->ref.'.pdf ';
+ print ''.$object->ref.'.pdf ';
print ''.dol_print_size(dol_filesize($file)).' ';
print ''.dol_print_date(dol_filemtime($file),'dayhour').' ';
print ' ';
@@ -139,7 +139,7 @@ if ($id > 0 || ! empty($ref))
{
print "Commande detaillee ";
- print ''.$object->ref.'-detail.pdf ';
+ print ''.$object->ref.'-detail.pdf ';
print ''.dol_print_size(dol_filesize($filedetail)).' ';
print ''.dol_print_date(dol_filemtime($filedetail),'dayhour').' ';
print ' ';
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 2a501f10f73..4801305a091 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -1,34 +1,34 @@
* Copyright (C) 2004-2013 Laurent Destailleur
- * Copyright (C) 2005 Marc Barilley / Ocebo
- * Copyright (C) 2005-2013 Regis Houssin
- * Copyright (C) 2006 Andre Cianfarani
- * Copyright (C) 2010-2013 Juanjo Menent
- * Copyright (C) 2011 Philippe Grand
- * Copyright (C) 2012 Christophe Battarel
- * Copyright (C) 2012 Marcos García
- * Copyright (C) 2013 Florian Henry
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
+* Copyright (C) 2005 Marc Barilley / Ocebo
+* Copyright (C) 2005-2013 Regis Houssin
+* Copyright (C) 2006 Andre Cianfarani
+* Copyright (C) 2010-2013 Juanjo Menent
+* Copyright (C) 2011 Philippe Grand
+* Copyright (C) 2012 Christophe Battarel
+* Copyright (C) 2012 Marcos García
+* Copyright (C) 2013 Florian Henry
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*/
/**
* \file htdocs/commande/fiche.php
- * \ingroup commande
- * \brief Page to show customer order
- */
+* \ingroup commande
+* \brief Page to show customer order
+*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
@@ -541,7 +541,7 @@ else if ($action == 'setnote_public' && $user->rights->commande->creer)
else if ($action == 'setnote_private' && $user->rights->commande->creer)
{
- $result=$object->update_note_rivate(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES));
+ $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES), '_private');
if ($result < 0) dol_print_error($db,$object->error);
}
@@ -1121,7 +1121,7 @@ else if ($action == 'print_file' AND $user->rights->printipp->use)
{
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'));
+ $printer->print_file(GETPOST('file','alpha'),GETPOST('printer','alpha'));
}
else if ($action == 'update_extras')
@@ -1784,7 +1784,7 @@ else
require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
$notify=new Notify($db);
$text.=' ';
- $text.=$notify->confirmMessage('NOTIFY_VAL_ORDER',$object->socid);
+ $text.=$notify->confirmMessage('ORDER_VALIDATE',$object->socid);
}
$formquestion=array();
if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
@@ -1935,15 +1935,15 @@ else
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
- }
- 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)'";
+ 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)'";
}
// Relative and absolute discounts
@@ -2135,49 +2135,24 @@ else
$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))
{
-
- if ($action == 'edit_extras')
- {
- print '
';
- print '';
+ print '';
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 53e839e0241..6c190bac20b 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1,34 +1,34 @@
* Copyright (C) 2004 Eric Seigne
- * Copyright (C) 2004-2013 Laurent Destailleur
- * Copyright (C) 2005 Marc Barilley / Ocebo
- * Copyright (C) 2005-2012 Regis Houssin
- * Copyright (C) 2006 Andre Cianfarani
- * Copyright (C) 2010-2013 Juanjo Menent
- * Copyright (C) 2012 Christophe Battarel
- * Copyright (C) 2013 Jean-Francois FERRY
- * Copyright (C) 2013 Florian Henry
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
+* Copyright (C) 2004-2013 Laurent Destailleur
+* Copyright (C) 2005 Marc Barilley / Ocebo
+* Copyright (C) 2005-2012 Regis Houssin
+* Copyright (C) 2006 Andre Cianfarani
+* Copyright (C) 2010-2013 Juanjo Menent
+* Copyright (C) 2012 Christophe Battarel
+* Copyright (C) 2013 Jean-Francois FERRY
+* Copyright (C) 2013 Florian Henry
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*/
/**
* \file htdocs/compta/facture.php
- * \ingroup facture
- * \brief Page to create/see an invoice
- */
+* \ingroup facture
+* \brief Page to create/see an invoice
+*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
@@ -99,7 +99,7 @@ $hookmanager->initHooks(array('invoicecard'));
/*
* Actions
- */
+*/
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
@@ -108,47 +108,47 @@ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);
// 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 (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)
{
- $result = $object->fetch($id);
- 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.'
';
- }
- }
+ $result = $object->fetch($id);
+ 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.'
';
+ }
+ }
}
// Delete invoice
@@ -156,7 +156,20 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fact
{
$result = $object->fetch($id);
$object->fetch_thirdparty();
- $result = $object->delete();
+
+ $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);
+ }
+
+ $result = $object->delete(0,0,$idwarehouse);
if ($result > 0)
{
header('Location: '.DOL_URL_ROOT.'/compta/facture/list.php');
@@ -208,146 +221,146 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->
// Delete link of credit note to invoice
else if ($action == 'unlinkdiscount' && $user->rights->facture->creer)
{
- $discount=new DiscountAbsolute($db);
- $result=$discount->fetch($_GET["discountid"]);
- $discount->unlink_invoice();
+ $discount=new DiscountAbsolute($db);
+ $result=$discount->fetch($_GET["discountid"]);
+ $discount->unlink_invoice();
}
// Validation
else if ($action == 'valid' && $user->rights->facture->creer)
{
- $object->fetch($id);
+ $object->fetch($id);
- // On verifie signe facture
- if ($object->type == 2)
- {
- // Si avoir, le signe doit etre negatif
- if ($object->total_ht >= 0)
- {
- $mesgs[]=''.$langs->trans("ErrorInvoiceAvoirMustBeNegative").'
';
- $action='';
- }
- }
- 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='';
- }
- }
+ // On verifie signe facture
+ if ($object->type == 2)
+ {
+ // Si avoir, le signe doit etre negatif
+ if ($object->total_ht >= 0)
+ {
+ $mesgs[]=''.$langs->trans("ErrorInvoiceAvoirMustBeNegative").'
';
+ $action='';
+ }
+ }
+ 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='';
+ }
+ }
}
else if ($action == 'set_thirdparty' && $user->rights->facture->creer)
{
- $object->fetch($id);
- $object->setValueFrom('fk_soc',$socid);
+ $object->fetch($id);
+ $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']);
+ $object->fetch($id);
+ $object->setProject($_POST['projectid']);
}
else if ($action == 'setmode' && $user->rights->facture->creer)
{
- $object->fetch($id);
- $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
- if ($result < 0) dol_print_error($db,$object->error);
+ $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);
+ $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);
+ $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);
+ $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);
+ $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);
+ $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)
{
- $object->fetch($id);
- $result = $object->set_remise($user, $_POST['remise_percent']);
+ $object->fetch($id);
+ $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.'
';
- }
- }
- else
- {
- dol_print_error($db,$object->error);
- }
- }
- 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"]);
+ // 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.'
';
+ }
+ }
+ else
+ {
+ dol_print_error($db,$object->error);
+ }
+ }
+ 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.'
';
- }
- }
+ $result=$discount->link_to_invoice(0,$id);
+ if ($result < 0)
+ {
+ $mesgs[]=''.$discount->error.'
';
+ }
+ }
}
else if ($action == 'set_ref_client' && $user->rights->facture->creer)
{
- $object->fetch($id);
- $object->set_ref_client($_POST['ref_client']);
+ $object->fetch($id);
+ $object->set_ref_client($_POST['ref_client']);
}
else if ($action == 'setnote_public' && $user->rights->facture->creer)
@@ -367,864 +380,967 @@ else if ($action == 'setnote_private' && $user->rights->facture->creer)
// Classify to validated
else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->valider)
{
- $idwarehouse=GETPOST('idwarehouse');
+ $idwarehouse=GETPOST('idwarehouse');
- $object->fetch($id);
- $object->fetch_thirdparty();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
- // Check parameters
+ // Check parameters
- // Check for mandatory prof id
- for ($i = 1; $i < 5; $i++)
- {
+ // 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++;
+ $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');
- }
- }
+ setEventMessage($langs->trans('ErrorProdIdIsMandatory',$langs->transcountry('ProfId'.$i, $object->thirdparty->country_code)),'errors');
+ }
+ }
- //Check for warehouse
- if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1))
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")),'errors');
- $action='';
- }
- }
+ $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);
+ }
- 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);
- $outputlangs->setDefaultLang($newlang);
- }
- 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');
- }
- }
+ //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)
+ {
+ // 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($id); // Reload to get new records
+ facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ }
+ }
+ 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');
+ $idwarehouse=GETPOST('idwarehouse');
- $object->fetch($id);
- $object->fetch_thirdparty();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
- // Check parameters
- if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1))
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")),'errors');
- $action='';
- }
- }
+ $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);
+ }
- 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;
+ // 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='';
+ }
+ }
- $result = $db->query($sql);
- if ($result)
- {
- $i = 0;
- $num = $db->num_rows($result);
+ 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;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
- $totalpaye += $objp->amount;
- $i++;
- }
- }
- else
- {
- dol_print_error($db,'');
- }
+ $result = $db->query($sql);
+ if ($result)
+ {
+ $i = 0;
+ $num = $db->num_rows($result);
- $resteapayer = $object->total_ttc - $totalpaye;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+ $totalpaye += $objp->amount;
+ $i++;
+ }
+ }
+ else
+ {
+ dol_print_error($db,'');
+ }
- // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
- $ventilExportCompta = $object->getVentilExportCompta();
+ $resteapayer = $object->total_ttc - $totalpaye;
- // On verifie si aucun paiement n'a ete effectue
- if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
- {
- $object->set_draft($user, $idwarehouse);
+ // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
+ $ventilExportCompta = $object->getVentilExportCompta();
- // 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($id); // Reload to get new records
- facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
- }
- }
+ // On verifie si aucun paiement n'a ete effectue
+ 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);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ 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)
{
- $object->fetch($id);
- $result = $object->set_paid($user);
+ $object->fetch($id);
+ $result = $object->set_paid($user);
}
// 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);
- }
- else
- {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Reason")),'errors');
- }
+ $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);
+ }
+ else
+ {
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Reason")),'errors');
+ }
}
// 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);
- }
- else
- {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Reason")),'errors');
- }
+ $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);
+ }
+ else
+ {
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Reason")),'errors');
+ }
}
// Convertir en reduc
else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer)
{
- $db->begin();
+ $db->begin();
- $object->fetch($id);
- $object->fetch_thirdparty();
- $object->fetch_lines();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $object->fetch_lines();
- 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++;
- }
+ 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++;
+ }
- // 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)';
- else {
- $this->error="CantConvertToReducAnInvoiceOfThisType";
- return -1;
- }
- $discount->tva_tx=abs($object->total_ttc);
- $discount->fk_soc=$object->socid;
- $discount->fk_facture_source=$object->id;
+ // 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)';
+ else {
+ $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);
+ $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;
- }
- }
+ $result=$discount->create($user);
+ if ($result < 0)
+ {
+ $error++;
+ break;
+ }
+ }
- if (! $error)
- {
- // Classe facture
- $result=$object->set_paid($user);
- if ($result > 0)
- {
- //$mesgs[]='OK'.$discount->id;
- $db->commit();
- }
- else
- {
- $mesgs[]=''.$object->error.'
';
- $db->rollback();
- }
- }
- else
- {
- $mesgs[]=''.$discount->error.'
';
- $db->rollback();
- }
- }
+ if (! $error)
+ {
+ // Classe facture
+ $result=$object->set_paid($user);
+ if ($result > 0)
+ {
+ //$mesgs[]='OK'.$discount->id;
+ $db->commit();
+ }
+ else
+ {
+ $mesgs[]=''.$object->error.'
';
+ $db->rollback();
+ }
+ }
+ 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');
+ $object->socid=GETPOST('socid','int');
- $db->begin();
+ $db->begin();
- $error=0;
+ $error=0;
- // Get extra fields
- foreach($_POST as $key => $value)
- {
- if (preg_match("/^options_/",$key))
- {
- $object->array_options[$key]=GETPOST($key);
- }
- }
+ // Get extra fields
+ foreach($_POST as $key => $value)
+ {
+ if (preg_match("/^options_/",$key))
+ {
+ $object->array_options[$key]=GETPOST($key);
+ }
+ }
- // 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');
- }
+ // 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)
- {
- // This is a replacement invoice
- $result=$object->fetch($_POST['fac_replacement']);
- $object->fetch_thirdparty();
+ if (! $error)
+ {
+ // This is a replacement invoice
+ $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;
+ // 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;
- }
- }
+ $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');
- }
+ // Credit note invoice
+ 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)
- {
- // Si facture avoir
- $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (! $error)
+ {
+ // Si facture avoir
+ $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- //$result=$object->fetch($_POST['fac_avoir']);
+ //$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'];
+ $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;
+ // Proprietes particulieres a facture avoir
+ $object->fk_facture_source = $_POST['fac_avoir'];
+ $object->type = 2;
- $id = $object->create($user);
+ $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($id,$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);
- }
- }
- }
- }
+ // 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($id,$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');
- }
+ // 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 (! $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'];
+ // Source facture
+ $object->fac_rec = $_POST['fac_rec'];
- $id = $object->create($user);
- }
- }
+ $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');
- }
- $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)
- {
- // 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->fetch_thirdparty();
+ // 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 creation from another object of another module (Example: origin=propal, originid=1)
- 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];
- }
+ $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (empty($datefacture))
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
+ }
- // For compatibility
- if ($element == 'order') { $element = $subelement = 'commande'; }
- if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
- if ($element == 'contract') { $element = $subelement = 'contrat'; }
- if ($element == 'inter') { $element = $subelement = 'ficheinter'; }
- if ($element == 'shipping') { $element = $subelement = 'expedition'; }
+ 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->fetch_thirdparty();
- $object->origin = $_POST['origin'];
- $object->origin_id = $_POST['originid'];
+ // If creation from another object of another module (Example: origin=propal, originid=1)
+ 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];
+ }
- // 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']);
- }
+ // For compatibility
+ if ($element == 'order') {
+ $element = $subelement = 'commande';
+ }
+ if ($element == 'propal') {
+ $element = 'comm/propal'; $subelement = 'propal';
+ }
+ if ($element == 'contract') {
+ $element = $subelement = 'contrat';
+ }
+ if ($element == 'inter') {
+ $element = $subelement = 'ficheinter';
+ }
+ if ($element == 'shipping') {
+ $element = $subelement = 'expedition';
+ }
- $id = $object->create($user);
+ $object->origin = $_POST['origin'];
+ $object->origin_id = $_POST['originid'];
- if ($id > 0)
- {
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
+ // 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']);
+ }
- $classname = ucfirst($subelement);
- $srcobject = new $classname($db);
+ $id = $object->create($user);
- 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();
+ 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');
+
+ $classname = ucfirst($subelement);
+ $srcobject = new $classname($db);
+
+ dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add deposit line");
+ $result=$srcobject->fetch($object->origin_id);
+ if ($result > 0)
+ {
+ $totalamount=0;
+ $lines = $srcobject->lines;
+ $num=count($lines);
+ for ($i=0;$i<$num;$i++)
+ {
+ $totalamount=+$lines[$i]->subprice;
+ }
+
+ if ($totalamount!=0) {
+ $amountdeposit=($totalamount*$valuedeposit)/100;
+ }
+ }
+ else
+ {
+ $mesgs[]=$srcobject->error;
+ $error++;
+ }
+
+ }
+
+ $result = $object->addline(
+ $id,
+ $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')
+ );
+
- $fk_parent_line=0;
- $num=count($lines);
+ }else {
- 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);
+ dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
- 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++;
- break;
- }
- }
- else
- {
- // Positive line
- $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
+ $classname = ucfirst($subelement);
+ $srcobject = new $classname($db);
- // 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;
+ 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();
- //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;
+ $fk_parent_line=0;
+ $num=count($lines);
- // 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;
- }
+ 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);
- $result = $object->addline(
- $id,
- $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
- );
+ 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++;
+ break;
+ }
+ }
+ else
+ {
+ // Positive line
+ $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
- if ($result > 0)
- {
- $lineid=$result;
- }
- else
- {
- $lineid=0;
- $error++;
- break;
- }
+ // 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;
- // Defined the new fk_parent_line
- if ($result > 0 && $lines[$i]->product_type == 9) {
- $fk_parent_line = $result;
- }
- }
- }
+ //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;
- // 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++;
- }
- }
- else
- {
- $mesgs[]=$object->error;
- $error++;
- }
- }
- // If some invoice's lines already known
- else
- {
- $id = $object->create($user);
+ // 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;
+ }
- 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($id,$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);
- }
- }
- }
- }
- }
+ $result = $object->addline(
+ $id,
+ $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
+ );
- // End of object creation, we show it
- if ($id > 0 && ! $error)
- {
- $db->commit();
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
- exit;
- }
- else
- {
- $db->rollback();
- $action='create';
- $_GET["origin"]=$_POST["origin"];
- $_GET["originid"]=$_POST["originid"];
- $mesgs[]=''.$object->error.'
';
- }
+ if ($result > 0)
+ {
+ $lineid=$result;
+ }
+ else
+ {
+ $lineid=0;
+ $error++;
+ break;
+ }
+
+ // Defined the new fk_parent_line
+ 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++;
+ }
+ }
+ }
+ else
+ {
+ $mesgs[]=$object->error;
+ $error++;
+ }
+ }
+ // 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($id,$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)
+ {
+ $db->commit();
+ header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+ $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)
{
$langs->load('errors');
- $error = 0;
+ $error = 0;
- $idprod=GETPOST('idprod', 'int');
+ $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);
if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && (GETPOST('qty') < 0))
- {
- setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
- }
- if (empty($idprod) && GETPOST('type') < 0)
- {
- setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
- $error++;
- }
+ {
+ setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
+ $error++;
+ }
+ if (empty($idprod) && GETPOST('type') < 0)
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
+ $error++;
+ }
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++;
}
- if (! GETPOST('qty') && GETPOST('qty') == '')
- {
- setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
- }
- if (empty($idprod) && empty($product_desc))
- {
- setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
- $error++;
- }
+ if (! GETPOST('qty') && GETPOST('qty') == '')
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
+ $error++;
+ }
+ if (empty($idprod) && empty($product_desc))
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
+ $error++;
+ }
- if (! $error && (GETPOST('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();
+ if (! $error && (GETPOST('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();
- // Clean parameters
- $predef=((! empty($idprod) && $conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
- $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');
+ // Clean parameters
+ $predef=((! empty($idprod) && $conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
+ $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
+ // Define special_code for special lines
+ $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))
- {
- $prod = new Product($db);
- $prod->fetch($idprod);
+ // 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))
+ {
+ $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');
+ // 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);
$desc = $product_desc;
- }
- else
+ }
+ else
{
- $tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
- $tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
+ $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];
- }
- else
- {
- $pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
- $price_min = $prod->price_min;
- $price_base_type = $prod->price_base_type;
- }
+ // 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];
+ }
+ else
+ {
+ $pu_ht = $prod->price;
+ $pu_ttc = $prod->price_ttc;
+ $price_min = $prod->price_min;
+ $price_base_type = $prod->price_base_type;
+ }
- // 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).
- if ($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');
- }
- }
+ // 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).
+ if ($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))
- {
- $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);
- $outputlangs->setDefaultLang($newlang);
- }
+ // Define output 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);
+ $outputlangs->setDefaultLang($newlang);
+ }
- $desc = (! empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
- }
- else
- {
- $desc = $prod->description;
- }
+ $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);
- }
- }
+ // 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);
+ }
+ }
- $type = $prod->type;
- }
- else
- {
- $pu_ht = price2num($price_ht, 'MU');
+ $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');
- }
+ }
- // Margin
- $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):'');
+ // Margin
+ $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):'');
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):'');
- // Local Taxes
- $localtax1_tx= get_localtax($tva_tx, 1, $object->client);
- $localtax2_tx= get_localtax($tva_tx, 2, $object->client);
+ // 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;
+ $info_bits=0;
+ if ($tva_npr) $info_bits |= 0x01;
- if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
- {
- $mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').$langs->getCurrencySymbol($conf->currency));
+ if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
+ {
+ $mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').$langs->getCurrencySymbol($conf->currency));
setEventMessage($mesg, 'errors');
- }
- else
- {
- // Insert line
- $result = $object->addline(
- $id,
- $desc,
- $pu_ht,
- GETPOST('qty'),
- $tva_tx,
- $localtax1_tx,
- $localtax2_tx,
- $idprod,
- GETPOST('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
- );
+ }
+ else
+ {
+ // Insert line
+ $result = $object->addline(
+ $id,
+ $desc,
+ $pu_ht,
+ GETPOST('qty'),
+ $tva_tx,
+ $localtax1_tx,
+ $localtax2_tx,
+ $idprod,
+ GETPOST('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
+ );
- 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);
- $outputlangs->setDefaultLang($newlang);
- }
+ 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);
+ $outputlangs->setDefaultLang($newlang);
+ }
- $ret=$object->fetch($id); // Reload to get new records
- facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
+ $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['idprod']);
- unset($_POST['remise_percent']);
- unset($_POST['price_ht']);
+ unset($_POST['qty']);
+ unset($_POST['type']);
+ unset($_POST['idprod']);
+ unset($_POST['remise_percent']);
+ unset($_POST['price_ht']);
unset($_POST['price_ttc']);
unset($_POST['tva_tx']);
unset($_POST['product_ref']);
@@ -1236,99 +1352,99 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
// old method
unset($_POST['np_desc']);
unset($_POST['dp_desc']);
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
- $action='';
- }
- }
+ $action='';
+ }
+ }
}
else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['save'] == $langs->trans('Save'))
{
- if (! $object->fetch($id) > 0) dol_print_error($db);
- $object->fetch_thirdparty();
+ 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);
+ // 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);
- // Define info_bits
- $info_bits=0;
- if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01;
+ // 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);
+ // 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
+ // Add buying price
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):'');
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):'');
- // Check minimum price
+ // Check minimum price
$productid = GETPOST('productid', 'int');
- if (! empty($productid))
- {
- $product = new Product($db);
- $product->fetch($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];
+ $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'):'');
+ $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", price2num($price_min,'MU')).$langs->getCurrencySymbol($conf->currency), 'errors');
- $error++;
- }
- }
- else
- {
- $type = GETPOST('type');
- $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", price2num($price_min,'MU')).$langs->getCurrencySymbol($conf->currency), 'errors');
+ $error++;
+ }
+ }
+ else
+ {
+ $type = GETPOST('type');
+ $label = (GETPOST('product_label') ? GETPOST('product_label'):'');
- // Check parameters
- if (GETPOST('type') < 0) {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
- $error++;
- }
- }
+ // Check parameters
+ if (GETPOST('type') < 0) {
+ 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
+ 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
);
if ($result >= 0)
@@ -1367,295 +1483,297 @@ else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['sa
{
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;
+ 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)
{
- $object->fetch($id);
- $object->fetch_thirdparty();
- $object->line_up($_GET['rowid']);
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $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);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ // 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)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
- exit;
+ 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->fetch($id);
+ $object->fetch_thirdparty();
+ $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);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ // 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)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
- exit;
+ header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
+ exit;
}
/*
* Add file in email form
- */
+*/
if (GETPOST('addfile'))
{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ 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';
+ // 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';
+ 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';
+ 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';
+ // Set tmp user directory
+ $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'])
{
- $langs->load('mails');
+ $langs->load('mails');
- $actiontypecode='';$subject='';$actionmsg='';$actionmsg2='';
+ $actiontypecode='';$subject='';$actionmsg='';$actionmsg2='';
- $result=$object->fetch($id);
- $result=$object->fetch_thirdparty();
+ $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 ($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'];
- $sendtoid = 0;
- }
- elseif ($_POST['receiver'] != '-1')
- {
- // Recipient was provided from combo list
- if ($_POST['receiver'] == 'thirdparty') // Id of third party
- {
- $sendto = $object->client->email;
- $sendtoid = 0;
- }
- else // Id du contact
- {
- $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
- $sendtoid = $_POST['receiver'];
- }
- }
+ // if (is_readable($file))
+ // {
+ if ($_POST['sendto'])
+ {
+ // Le destinataire a ete fourni via le champ libre
+ $sendto = $_POST['sendto'];
+ $sendtoid = 0;
+ }
+ elseif ($_POST['receiver'] != '-1')
+ {
+ // Recipient was provided from combo list
+ if ($_POST['receiver'] == 'thirdparty') // Id of third party
+ {
+ $sendto = $object->client->email;
+ $sendtoid = 0;
+ }
+ else // Id du contact
+ {
+ $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
+ $sendtoid = $_POST['receiver'];
+ }
+ }
- if (dol_strlen($sendto))
- {
- $langs->load("commercial");
+ 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'];
+ $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";
- if ($message) {
- $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
- $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
- $actionmsg.=$message;
- }
- //$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
- }
+ 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";
+ 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';
- $formmail = new FormMail($db);
+ // Create form object
+ 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;
+ // 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;
- // 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;
+ // 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;
- // 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);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // Fin appel triggers
+ // 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);
+ if ($result < 0) {
+ $error++; $this->errors=$interface->errors;
+ }
+ // Fin appel triggers
- if ($error)
- {
- dol_print_error($db);
- }
- 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));
- setEventMessage($mesg);
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id);
- exit;
- }
- }
- else
- {
- $langs->load("other");
- $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';
- }
- $mesg.='
';
- $mesgs[]=$mesg;
- }
- }
-/* }
- else
- {
- $langs->load("other");
- $mesgs[]=''.$langs->trans('ErrorMailRecipientIsEmpty').'
';
- dol_syslog('Recipient email is empty');
- }*/
- }
- else
- {
- $langs->load("errors");
- $mesgs[]=''.$langs->trans('ErrorCantReadFile',$file).'
';
- dol_syslog('Failed to read file: '.$file);
- }
- }
- else
- {
- $langs->load("other");
- $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.');
- }
+ if ($error)
+ {
+ dol_print_error($db);
+ }
+ 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));
+ setEventMessage($mesg);
+ header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id);
+ exit;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $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';
+ }
+ $mesg.='
';
+ $mesgs[]=$mesg;
+ }
+ }
+ /* }
+ else
+ {
+ $langs->load("other");
+ $mesgs[]=''.$langs->trans('ErrorMailRecipientIsEmpty').'
';
+ dol_syslog('Recipient email is empty');
+ }*/
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesgs[]=''.$langs->trans('ErrorCantReadFile',$file).'
';
+ dol_syslog('Failed to read file: '.$file);
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $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';
+ $action = 'presend';
}
/*
* Generate document
- */
+*/
else if ($action == 'builddoc') // En get ou en post
{
- $object->fetch($id);
- $object->fetch_thirdparty();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
- if (GETPOST('model')) $object->setDocModel($user, GETPOST('model'));
+ if (GETPOST('model')) $object->setDocModel($user, GETPOST('model'));
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);
- $outputlangs->setDefaultLang($newlang);
- }
- $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
- }
- else
- {
- header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
- exit;
- }
+ // 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);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
+ else
+ {
+ header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
+ exit;
+ }
}
// Remove file in doc form
@@ -1767,7 +1885,7 @@ if ($action == 'update_extras')
/*
* View
- */
+*/
$form = new Form($db);
$formother=new FormOther($db);
@@ -1781,276 +1899,290 @@ llxHeader('',$langs->trans('Bill'),'EN:Customers_Invoices|FR:Factures_Clients|ES
/*********************************************************************
*
- * Mode creation
- *
- **********************************************************************/
+* Mode creation
+*
+**********************************************************************/
if ($action == 'create')
{
- $facturestatic=new Facture($db);
- $extralabels=$extrafields->fetch_name_optionals_label('facture');
+ $facturestatic=new Facture($db);
+ $extralabels=$extrafields->fetch_name_optionals_label('facture');
- print_fiche_titre($langs->trans('NewBill'));
+ print_fiche_titre($langs->trans('NewBill'));
- $soc = new Societe($db);
- if ($socid>0) $res=$soc->fetch($socid);
+ $soc = new Societe($db);
+ 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 ($element == 'project')
- {
- $projectid=$originid;
- }
- else
- {
- // For compatibility
- if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
- if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
- if ($element == 'contract') { $element = $subelement = 'contrat'; }
- if ($element == 'shipping') { $element = $subelement = 'expedition'; }
-
- 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();
- $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:'');
-
- $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;
- }
- }
- 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))
- {
- print ajax_combobox('fac_replacement');
- print ajax_combobox('fac_avoir');
- }
-
- print '