diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index 6f1a40b2fb0..79278fef056 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -777,8 +777,6 @@ if ($object->id > 0)
print '
';
print ' | ';
print '
';
}
@@ -1283,7 +1281,7 @@ if ($object->id > 0)
{
if ($object->client != 0 && $object->client != 2)
{
- if (!empty($orders2invoice) && $orders2invoice > 0) print '';
+ if (!empty($orders2invoice) && $orders2invoice > 0) print '';
else print '';
} else print '';
}
diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php
index 82fde75966b..ad422a8b930 100644
--- a/htdocs/commande/list.php
+++ b/htdocs/commande/list.php
@@ -1102,7 +1102,7 @@ if ($resql)
{
if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0))
{
- print ' ';
+ print ' ';
print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'';
}
}
@@ -1299,7 +1299,7 @@ if ($resql)
}
// Action column
- print '';
+ print ' | ';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
$selected = 0;
diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php
index 2bdae583429..c2f0a314445 100644
--- a/htdocs/core/actions_massactions.inc.php
+++ b/htdocs/core/actions_massactions.inc.php
@@ -615,7 +615,7 @@ if ($massaction == 'confirm_createbills') // Create bills from orders
$cmd->fetch_optionals();
$objecttmp->socid = $cmd->socid;
- $objecttmp->type = Facture::TYPE_STANDARD;
+ $objecttmp->type = $objecttmp::TYPE_STANDARD;
$objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
$objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
$objecttmp->fk_project = $cmd->fk_project;
@@ -742,7 +742,7 @@ if ($massaction == 'confirm_createbills') // Create bills from orders
'HT',
0,
$product_type,
- $ii,
+ $lines[$i]->rang,
$lines[$i]->special_code,
$objecttmp->origin,
$lines[$i]->rowid,
diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php
index 8488abeee30..1de6d30b681 100644
--- a/htdocs/fourn/card.php
+++ b/htdocs/fourn/card.php
@@ -798,7 +798,7 @@ if ($object->id > 0)
if ($object->status == 1)
{
// Company is open
- print '';
+ print '';
} else {
print '';
}
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 23f0cc1f3ea..0c0e32a2055 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -1601,9 +1601,10 @@ class FactureFournisseur extends CommonInvoice
* @param double $pu_ht_devise Amount in currency
* @param string $ref_supplier Supplier ref
* @param string $special_code Special code
+ * @param int $fk_parent_line Parent line id
* @return int >0 if OK, <0 if KO
*/
- public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product = 0, $remise_percent = 0, $date_start = '', $date_end = '', $ventil = 0, $info_bits = '', $price_base_type = 'HT', $type = 0, $rang = -1, $notrigger = false, $array_options = 0, $fk_unit = null, $origin_id = 0, $pu_ht_devise = 0, $ref_supplier = '', $special_code = '')
+ public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product = 0, $remise_percent = 0, $date_start = '', $date_end = '', $ventil = 0, $info_bits = '', $price_base_type = 'HT', $type = 0, $rang = -1, $notrigger = false, $array_options = 0, $fk_unit = null, $origin_id = 0, $pu_ht_devise = 0, $ref_supplier = '', $special_code = '', $fk_parent_line = 0)
{
global $langs, $mysoc, $conf;
@@ -1777,7 +1778,7 @@ class FactureFournisseur extends CommonInvoice
$this->line->info_bits = $info_bits;
$this->line->special_code = ((string) $special_code != '' ? $special_code : $this->special_code);
- $this->line->fk_parent_line = $this->fk_parent_line;
+ $this->line->fk_parent_line = $fk_parent_line;
$this->line->origin = $this->origin;
$this->line->origin_id = $origin_id;
$this->line->fk_unit = $fk_unit;
diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php
index 6be60c04249..48613e67d43 100644
--- a/htdocs/fourn/commande/list.php
+++ b/htdocs/fourn/commande/list.php
@@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
@@ -130,6 +131,9 @@ $fieldstosearchall = array(
'cf.ref_supplier'=>'RefSupplierOrder',
'pd.description'=>'Description',
's.nom'=>"ThirdParty",
+ 's.name_alias'=>"AliasNameShort",
+ 's.zip'=>"Zip",
+ 's.town'=>"Town",
'cf.note_public'=>'NotePublic',
);
if (empty($user->socid)) $fieldstosearchall["cf.note_private"] = "NotePrivate";
@@ -180,7 +184,7 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
*/
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
-if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createsupplierbills') { $massaction = ''; }
$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
@@ -244,7 +248,7 @@ if (empty($reshook))
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
// TODO Move this into mass action include
- if ($massaction == 'confirm_createbills')
+ if ($massaction == 'confirm_createsupplierbills')
{
$orders = GETPOST('toselect', 'array');
$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
@@ -258,34 +262,36 @@ if (empty($reshook))
$db->begin();
foreach ($orders as $id_order) {
- $cmd = new Commande($db);
+ $cmd = new CommandeFournisseur($db);
if ($cmd->fetch($id_order) <= 0) continue;
- $object = new Facture($db);
- if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
+ $objecttmp = new FactureFournisseur($db);
+ if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
else {
- $object->socid = $cmd->socid;
- $object->type = Facture::TYPE_STANDARD;
- $object->cond_reglement_id = $cmd->cond_reglement_id;
- $object->mode_reglement_id = $cmd->mode_reglement_id;
- $object->fk_project = $cmd->fk_project;
+ $objecttmp->socid = $cmd->socid;
+ $objecttmp->type = $objecttmp::TYPE_STANDARD;
+ $objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
+ $objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
+ $objecttmp->fk_project = $cmd->fk_project;
+ $objecttmp->multicurrency_code = $cmd->multicurrency_code;
+ if (empty($createbills_onebythird)) $objecttmp->ref_client = $cmd->ref_client;
- $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
if (empty($datefacture))
{
- $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
+ $datefacture = dol_now();
}
- $object->date = $datefacture;
- $object->origin = 'commande';
- $object->origin_id = $id_order;
+ $objecttmp->date = $datefacture;
+ $objecttmp->origin = 'order_supplier';
+ $objecttmp->origin_id = $id_order;
- $res = $object->create($user);
+ $res = $objecttmp->create($user);
if ($res > 0) $nb_bills_created++;
}
- if ($object->id > 0)
+ if ($objecttmp->id > 0)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
$sql .= "fk_source";
@@ -294,9 +300,9 @@ if (empty($reshook))
$sql .= ", targettype";
$sql .= ") VALUES (";
$sql .= $id_order;
- $sql .= ", '".$db->escape($object->origin)."'";
- $sql .= ", ".$object->id;
- $sql .= ", '".$db->escape($object->element)."'";
+ $sql .= ", '".$db->escape($objecttmp->origin)."'";
+ $sql .= ", ".$objecttmp->id;
+ $sql .= ", '".$db->escape($objecttmp->element)."'";
$sql .= ")";
if (!$db->query($sql))
@@ -323,7 +329,7 @@ if (empty($reshook))
{
// Negative line, we create a discount line
$discount = new DiscountAbsolute($db);
- $discount->fk_soc = $object->socid;
+ $discount->fk_soc = $objecttmp->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);
@@ -333,7 +339,7 @@ if (empty($reshook))
$discountid = $discount->create($user);
if ($discountid > 0)
{
- $result = $object->insert_discount($discountid);
+ $result = $objecttmp->insert_discount($discountid);
//$result=$discount->link_to_invoice($lineid,$id);
} else {
setEventMessages($discount->error, $discount->errors, 'errors');
@@ -358,32 +364,31 @@ if (empty($reshook))
{
$fk_parent_line = 0;
}
- $result = $object->addline(
+ $result = $objecttmp->addline(
$desc,
$lines[$i]->subprice,
- $lines[$i]->qty,
$lines[$i]->tva_tx,
$lines[$i]->localtax1_tx,
$lines[$i]->localtax2_tx,
- $lines[$i]->fk_product,
+ $lines[$i]->qty,
+ $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,
- $ii,
- $lines[$i]->special_code,
- $object->origin,
- $lines[$i]->rowid,
- $fk_parent_line,
- $lines[$i]->fk_fournprice,
- $lines[$i]->pa_ht,
- $lines[$i]->label
- );
+ 'HT',
+ $product_type,
+ $lines[$i]->rang,
+ false,
+ $lines[$i]->array_options,
+ $lines[$i]->fk_unit,
+ $objecttmp->origin_id,
+ $lines[$i]->pa_ht,
+ $lines[$i]->ref_supplier,
+ $lines[$i]->special_code,
+ $fk_parent_line
+ );
if ($result > 0)
{
$lineid = $result;
@@ -404,8 +409,8 @@ if (empty($reshook))
$cmd->classifyBilled($user); // TODO Move this in workflow like done for customer orders
- if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object;
- else $TFact[$object->id] = $object;
+ if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $objecttmp;
+ else $TFact[$objecttmp->id] = $objecttmp;
}
// Build doc with all invoices
@@ -415,38 +420,67 @@ if (empty($reshook))
if (!$error && $validate_invoices) {
$massaction = $action = 'builddoc';
- foreach ($TAllFact as &$object)
+ foreach ($TAllFact as &$objecttmp)
{
- $object->validate($user);
+ $objecttmp->validate($user);
if ($result <= 0)
{
$error++;
- setEventMessages($object->error, $object->errors, 'errors');
+ setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
break;
}
- $id = $object->id; // For builddoc action
+ $id = $objecttmp->id; // For builddoc action
// Fac builddoc
$donotredirect = 1;
- $upload_dir = $conf->facture->dir_output;
- $permissiontoadd = $user->rights->facture->creer;
- include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
+ $upload_dir = $conf->fournisseur->facture->dir_output;
+ $permissiontoadd = $user->rights->fournisseur->facture->creer;
+ //include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
}
- $massaction = $action = 'confirm_createbills';
+ $massaction = $action = 'confirm_createsupplierbills';
}
if (!$error)
{
$db->commit();
setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
+
+ // Make a redirect to avoid to bill twice if we make a refresh or back
+ $param = '';
+ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
+ if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
+ if ($sall) $param .= '&sall='.urlencode($sall);
+ if ($socid > 0) $param .= '&socid='.urlencode($socid);
+ if ($search_status != '') $param .= '&search_status='.urlencode($search_status);
+ if ($search_orderday) $param .= '&search_orderday='.urlencode($search_orderday);
+ if ($search_ordermonth) $param .= '&search_ordermonth='.urlencode($search_ordermonth);
+ if ($search_orderyear) $param .= '&search_orderyear='.urlencode($search_orderyear);
+ if ($search_deliveryday) $param .= '&search_deliveryday='.urlencode($search_deliveryday);
+ if ($search_deliverymonth) $param .= '&search_deliverymonth='.urlencode($search_deliverymonth);
+ if ($search_deliveryyear) $param .= '&search_deliveryyear='.urlencode($search_deliveryyear);
+ if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
+ if ($search_company) $param .= '&search_company='.urlencode($search_company);
+ if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer);
+ if ($search_user > 0) $param .= '&search_user='.urlencode($search_user);
+ if ($search_sale > 0) $param .= '&search_sale='.urlencode($search_sale);
+ if ($search_total_ht != '') $param .= '&search_total_ht='.urlencode($search_total_ht);
+ if ($search_total_vat != '') $param .= '&search_total_vat='.urlencode($search_total_vat);
+ if ($search_total_ttc != '') $param .= '&search_total_ttc='.urlencode($search_total_ttc);
+ if ($search_project_ref >= 0) $param .= "&search_project_ref=".urlencode($search_project_ref);
+ if ($show_files) $param .= '&show_files='.urlencode($show_files);
+ if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
+ if ($billed != '') $param .= '&billed='.urlencode($billed);
+
+ header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
+ exit;
} else {
$db->rollback();
$action = 'create';
$_GET["origin"] = $_POST["origin"];
$_GET["originid"] = $_POST["originid"];
- setEventMessages($object->error, $object->errors, 'errors');
+ setEventMessages("Error", null, 'errors');
$error++;
}
}
@@ -566,6 +600,7 @@ $sql .= $hookmanager->resPrint;
$sql .= $db->order($sortfield, $sortorder);
+// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
@@ -579,6 +614,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
}
$sql .= $db->plimit($limit + 1, $offset);
+//print $sql;
$resql = $db->query($sql);
if ($resql)
@@ -607,23 +643,24 @@ if ($resql)
llxHeader('', $title, $help_url);
$param = '';
- if ($socid > 0) $param .= '&socid='.$socid;
- if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
- if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
- if ($sall) $param .= "&search_all=".$sall;
- if ($search_orderday) $param .= '&search_orderday='.$search_orderday;
- if ($search_ordermonth) $param .= '&search_ordermonth='.$search_ordermonth;
- if ($search_orderyear) $param .= '&search_orderyear='.$search_orderyear;
- if ($search_deliveryday) $param .= '&search_deliveryday='.$search_deliveryday;
- if ($search_deliverymonth) $param .= '&search_deliverymonth='.$search_deliverymonth;
- if ($search_deliveryyear) $param .= '&search_deliveryyear='.$search_deliveryyear;
- if ($search_ref) $param .= '&search_ref='.$search_ref;
- if ($search_company) $param .= '&search_company='.$search_company;
- if ($search_user > 0) $param .= '&search_user='.$search_user;
- if ($search_request_author) $param .= '&search_request_author='.$search_request_author;
- if ($search_sale > 0) $param .= '&search_sale='.$search_sale;
- if ($search_total_ht != '') $param .= '&search_total_ht='.$search_total_ht;
- if ($search_total_ttc != '') $param .= "&search_total_ttc=".$search_total_ttc;
+ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
+ if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
+ if ($sall) $param .= '&sall='.urlencode($sall);
+ if ($socid > 0) $param .= '&socid='.urlencode($socid);
+ if ($sall) $param .= "&search_all=".urlencode($sall);
+ if ($search_orderday) $param .= '&search_orderday='.urlencode($search_orderday);
+ if ($search_ordermonth) $param .= '&search_ordermonth='.urlencode($search_ordermonth);
+ if ($search_orderyear) $param .= '&search_orderyear='.urlencode($search_orderyear);
+ if ($search_deliveryday) $param .= '&search_deliveryday='.urlencode($search_deliveryday);
+ if ($search_deliverymonth) $param .= '&search_deliverymonth='.urlencode($search_deliverymonth);
+ if ($search_deliveryyear) $param .= '&search_deliveryyear='.urlencode($search_deliveryyear);
+ if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
+ if ($search_company) $param .= '&search_company='.urlencode($search_company);
+ if ($search_user > 0) $param .= '&search_user='.urlencode($search_user);
+ if ($search_request_author) $param .= '&search_request_author='.urlencode($search_request_author);
+ if ($search_sale > 0) $param .= '&search_sale='.urlencode($search_sale);
+ if ($search_total_ht != '') $param .= '&search_total_ht='.urlencode($search_total_ht);
+ if ($search_total_ttc != '') $param .= "&search_total_ttc=".urlencode($search_total_ttc);
if ($search_multicurrency_code != '') $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
if ($search_multicurrency_tx != '') $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
if ($search_multicurrency_montant_ht != '') $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
@@ -644,7 +681,7 @@ if ($resql)
'builddoc'=>$langs->trans("PDFMerge"),
'presend'=>$langs->trans("SendByMail"),
);
- //if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
+ if ($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisSupplier");
if ($user->rights->fournisseur->commande->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete");
if (in_array($massaction, array('presend', 'predelete', 'createbills'))) $arrayofmassactions = array();
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
@@ -653,15 +690,16 @@ if ($resql)
if (!empty($socid)) $url .= '&socid='.$socid;
$newcardbutton = dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', $user->rights->fournisseur->commande->creer);
- // Fields title search
- print ' |