';
diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index 0ddb1618f34..20f325658f6 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -46,7 +46,7 @@ class Contrat extends CommonObject
var $id;
var $ref;
var $ref_ext;
- var $ref_customer;
+ var $ref_supplier;
var $socid;
var $societe; // Objet societe
var $statut=0; // 0=Draft,
@@ -403,7 +403,7 @@ class Contrat extends CommonObject
$sql.= " fk_projet,";
$sql.= " fk_commercial_signature, fk_commercial_suivi,";
$sql.= " note_private, note_public, model_pdf, extraparams";
- $sql.= " ,ref_customer";
+ $sql.= " ,ref_supplier";
$sql.= " ,ref_ext";
$sql.= " FROM ".MAIN_DB_PREFIX."contrat";
if ($ref)
@@ -423,7 +423,7 @@ class Contrat extends CommonObject
{
$this->id = $result["rowid"];
$this->ref = (!isset($result["ref"]) || !$result["ref"]) ? $result["rowid"] : $result["ref"];
- $this->ref_customer = $result["ref_customer"];
+ $this->ref_supplier = $result["ref_supplier"];
$this->ref_ext = $result["ref_ext"];
$this->statut = $result["statut"];
$this->mise_en_service = $this->db->jdate($result["datemise"]);
@@ -726,7 +726,7 @@ class Contrat extends CommonObject
// Insert contract
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, date_contrat,";
$sql.= " fk_commercial_signature, fk_commercial_suivi, fk_projet,";
- $sql.= " ref, entity, note_private, note_public, ref_customer, ref_ext)";
+ $sql.= " ref, entity, note_private, note_public, ref_supplier, ref_ext)";
$sql.= " VALUES ('".$this->db->idate($now)."',".$this->socid.",".$user->id;
$sql.= ", '".$this->db->idate($this->date_contrat)."'";
$sql.= ",".($this->commercial_signature_id>0?$this->commercial_signature_id:"NULL");
@@ -736,7 +736,7 @@ class Contrat extends CommonObject
$sql.= ", ".$conf->entity;
$sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
$sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
- $sql.= ", ".(!empty($this->ref_customer)?("'".$this->db->escape($this->ref_customer)."'"):"NULL");
+ $sql.= ", ".(!empty($this->ref_supplier)?("'".$this->db->escape($this->ref_supplier)."'"):"NULL");
$sql.= ", ".(!empty($this->ref_ext)?("'".$this->db->escape($this->ref_ext)."'"):"NULL");
$sql.= ")";
$resql=$this->db->query($sql);
@@ -988,7 +988,7 @@ class Contrat extends CommonObject
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
- if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer);
+ if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier);
if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
if (isset($this->entity)) $this->entity=trim($this->entity);
if (isset($this->statut)) $this->statut=trim($this->statut);
@@ -1012,7 +1012,7 @@ class Contrat extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
- $sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").",";
+ $sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").",";
$sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").",";
$sql.= " entity=".$conf->entity.",";
$sql.= " date_contrat=".(dol_strlen($this->date_contrat)!=0 ? "'".$this->db->idate($this->date_contrat)."'" : 'null').",";
diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php
index 7970e80603c..5f9c2099107 100644
--- a/htdocs/contrat/list.php
+++ b/htdocs/contrat/list.php
@@ -42,7 +42,7 @@ $offset = $limit * $page ;
$search_nom=GETPOST('search_nom');
$search_contract=GETPOST('search_contract');
-$search_ref_customer=GETPOST('search_ref_customer','alpha');
+$search_ref_supplier=GETPOST('search_ref_supplier','alpha');
$sall=GETPOST('sall');
$statut=GETPOST('statut')?GETPOST('statut'):1;
$socid=GETPOST('socid');
@@ -75,7 +75,7 @@ $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND
$sql.= ' SUM('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
$sql.= " c.rowid as cid, c.ref, c.datec, c.date_contrat, c.statut,";
$sql.= " s.nom, s.rowid as socid";
-$sql.= " ,c.ref_customer";
+$sql.= " ,c.ref_supplier";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ", ".MAIN_DB_PREFIX."contrat as c";
@@ -90,8 +90,8 @@ if ($search_nom) {
if ($search_contract) {
$sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
}
-if (!empty($search_ref_customer)) {
- $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
+if (!empty($search_ref_supplier)) {
+ $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
}
if ($sall) {
$sql .= natural_search(array('s.nom', 'cd.label', 'cd.description'), $sall);
@@ -114,9 +114,9 @@ if ($resql)
print '
';
$param='&search_contract='.$search_contract;
$param.='&search_nom='.$search_nom;
- $param.='&search_ref_customer='.$search_ref_customer;
+ $param.='&search_ref_supplier='.$search_ref_supplier;
print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "c.rowid","","$param",'',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("RefCustomer"), $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans("RefCustomer"), $_SERVER["PHP_SELF"], "c.ref_supplier","","$param",'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
//print_liste_field_titre($langs->trans("DateCreation"), $_SERVER["PHP_SELF"], "c.datec","","$param",'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateContract"), $_SERVER["PHP_SELF"], "c.date_contrat","","$param",'align="center"',$sortfield,$sortorder);
@@ -134,7 +134,7 @@ if ($resql)
print ' ';
print '';
print '';
- print ' ';
+ print ' ';
print ' ';
print '';
print ' ';
@@ -156,7 +156,7 @@ if ($resql)
print img_object($langs->trans("ShowContract"),"contract").' '.(isset($obj->ref) ? $obj->ref : $obj->cid) .'';
if ($obj->nb_late) print img_warning($langs->trans("Late"));
print ' ';
- print ''.$obj->ref_customer.' ';
+ print ''.$obj->ref_supplier.' ';
print ''.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.' ';
//print ''.dol_print_date($obj->datec).' ';
print ''.dol_print_date($db->jdate($obj->date_contrat)).' ';
diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php
index b6fde307110..91f10cae4a3 100644
--- a/htdocs/core/menus/standard/eldy.lib.php
+++ b/htdocs/core/menus/standard/eldy.lib.php
@@ -790,6 +790,15 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (! empty($conf->facture->enabled)) $newmenu->add("/commande/list.php?leftmenu=orders&viewstatut=-3", $langs->trans("MenuOrdersToBill2"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders');
// if (empty($leftmenu) || $leftmenu=="orders") $newmenu->add("/commande/", $langs->trans("StatusOrderToBill"), 1, $user->rights->commande->lire);
}
+
+ // Supplier Orders
+ if (! empty($conf->fournisseur->enabled))
+ {
+ $langs->load("supplier");
+ $newmenu->add("/fourn/commande/list.php?leftmenu=orders&search_status=5", $langs->trans("MenuOrdersSupplierToBill"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders');
+ // if (empty($leftmenu) || $leftmenu=="orders") $newmenu->add("/commande/", $langs->trans("StatusOrderToBill"), 1, $user->rights->commande->lire);
+ }
+
// Donations
if (! empty($conf->don->enabled))
diff --git a/htdocs/core/modules/export/export_excel.modules.php b/htdocs/core/modules/export/export_excel.modules.php
index bab287ff3b6..87923b4cb9c 100644
--- a/htdocs/core/modules/export/export_excel.modules.php
+++ b/htdocs/core/modules/export/export_excel.modules.php
@@ -190,6 +190,14 @@ class ExportExcel extends ModeleExports
return -1;
}
}
+
+ if (!empty($conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR)) {
+ $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
+ $cacheSettings = array (
+ 'dir' => $conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR
+ );
+ PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
+ }
$this->workbook = new PHPExcel();
$this->workbook->getProperties()->setCreator($user->getFullName($outputlangs).' - Dolibarr '.DOL_VERSION);
diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php
index cbfa35f4c11..840151b6001 100644
--- a/htdocs/fourn/card.php
+++ b/htdocs/fourn/card.php
@@ -304,6 +304,28 @@ if ($object->fetch($id))
if ($user->rights->fournisseur->commande->lire)
{
+
+
+ // TODO move to DAO class
+ // Check if there are supplier orders billable
+ $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
+ $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut';
+ $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
+ $sql2.= ', '.MAIN_DB_PREFIX.'commande_fournisseur as c';
+ $sql2.= ' WHERE c.fk_soc = s.rowid';
+ $sql2.= ' AND s.rowid = '.$object->id;
+ // Show orders with status validated, shipping started and delivered (well any order we can bill)
+ $sql2.= " AND c.fk_statut IN (5)";
+ // Find order that are not already invoiced
+ $sql2 .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
+ $resql2=$db->query($sql2);
+ if ($resql2) {
+ $orders2invoice = $db->num_rows($resql2);
+ $db->free($resql2);
+ } else {
+ setEventMessage($db->lasterror(),'errors');
+ }
+
// TODO move to DAO class
$sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p ";
@@ -436,60 +458,66 @@ if ($object->fetch($id))
if (empty($reshook))
{
- print '';
- print ' ';
-
- if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
- {
- print ' ';
- // List of contacts
- show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
- }
-
- // Addresses list
- if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
- {
- $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
- }
-
- if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
- {
- print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
-
- // List of todo actions
- show_actions_todo($conf,$langs,$db,$object);
-
- // List of done actions
- show_actions_done($conf,$langs,$db,$object);
- }
+ print '';
+
+ if ($user->rights->fournisseur->commande->creer)
+ {
+ $langs->load("orders");
+ print '
'.$langs->trans("AddOrder").' ';
}
+
+ if ($user->rights->fournisseur->facture->creer)
+ {
+ $langs->load("bills");
+ print '
'.$langs->trans("AddBill").' ';
+ }
+
+ if ($user->rights->fournisseur->facture->creer)
+ {
+ if (! empty($orders2invoice) && $orders2invoice > 0) print '
';
+ else print '
';
+ }
+
+ // Add action
+ if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
+ {
+ if ($user->rights->agenda->myactions->create)
+ {
+ print '
'.$langs->trans("AddAction").' ';
+ }
+ else
+ {
+ print '
'.$langs->trans("AddAction").' ';
+ }
+ }
+
+ print '
';
+ print ' ';
+
+ if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
+ {
+ print ' ';
+ // List of contacts
+ show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
+ }
+
+ // Addresses list
+ if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
+ {
+ $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
+ }
+
+ if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
+ {
+ print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
+
+ // List of todo actions
+ show_actions_todo($conf,$langs,$db,$object);
+
+ // List of done actions
+ show_actions_done($conf,$langs,$db,$object);
+ }
+}
}
else
{
diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php
index 37f2384b4b1..44a2dcbf725 100644
--- a/htdocs/fourn/commande/list.php
+++ b/htdocs/fourn/commande/list.php
@@ -51,6 +51,8 @@ $socid = GETPOST('socid','int');
$sortorder = GETPOST('sortorder','alpha');
$sortfield = GETPOST('sortfield','alpha');
+$viewstatut=GETPOST('viewstatut');
+
// Security check
$orderid = GETPOST('orderid');
if ($user->societe_id) $socid=$user->societe_id;
@@ -255,6 +257,8 @@ if ($resql)
}
print "\n";
print "\n";
+
+ print ' '.img_help(1,'').' '.$langs->trans("ToBillSeveralOrderSelectCustomer", $langs->transnoentitiesnoconv("CreateInvoiceForThisCustomer")).' ';
$db->free($resql);
}
diff --git a/htdocs/fourn/commande/orderstoinvoice.php b/htdocs/fourn/commande/orderstoinvoice.php
new file mode 100644
index 00000000000..6c5ce8aa11c
--- /dev/null
+++ b/htdocs/fourn/commande/orderstoinvoice.php
@@ -0,0 +1,594 @@
+
+ * Copyright (C) 2004-2013 Laurent Destailleur
+ * Copyright (C) 2005 Marc Barilley / Ocebo
+ * Copyright (C) 2005-2012 Regis Houssin
+ * Copyright (C) 2012 Andreu Bisquerra Gaya
+ * Copyright (C) 2012 David Rodriguez Martinez
+ * Copyright (C) 2012 Juanjo Menent
+ * Copyright (C) 2014 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/fourn/commande/orderstoinvoice.php
+ * \ingroup commande
+ * \brief Page to invoice multiple supplier orders
+ */
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
+require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php';
+if (! empty($conf->projet->enabled)) {
+ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
+}
+
+$langs->load('orders');
+$langs->load('deliveries');
+$langs->load('companies');
+
+if (! $user->rights->facture->creer)
+ accessforbidden();
+
+$id = (GETPOST('id') ? GETPOST('id', 'int') : GETPOST("facid")); // For backward compatibility
+$ref = GETPOST('ref', 'alpha');
+$action = GETPOST('action', 'alpha');
+$confirm = GETPOST('confirm', 'alpha');
+$sref = GETPOST('sref');
+$sref_client = GETPOST('sref_client');
+$sall = GETPOST('sall');
+$socid = GETPOST('socid', 'int');
+$selected = GETPOST('orders_to_invoice');
+$sortfield = GETPOST("sortfield", 'alpha');
+$sortorder = GETPOST("sortorder", 'alpha');
+$viewstatut = GETPOST('viewstatut');
+
+if (! $sortfield)
+ $sortfield = 'c.rowid';
+if (! $sortorder)
+ $sortorder = 'DESC';
+
+$now = dol_now();
+$date_start = dol_mktime(0, 0, 0, $_REQUEST["date_startmonth"], $_REQUEST["date_startday"], $_REQUEST["date_startyear"]); // Date for local PHP server
+$date_end = dol_mktime(23, 59, 59, $_REQUEST["date_endmonth"], $_REQUEST["date_endday"], $_REQUEST["date_endyear"]);
+$date_starty = dol_mktime(0, 0, 0, $_REQUEST["date_start_delymonth"], $_REQUEST["date_start_delyday"], $_REQUEST["date_start_delyyear"]); // Date for local PHP server
+$date_endy = dol_mktime(23, 59, 59, $_REQUEST["date_end_delymonth"], $_REQUEST["date_end_delyday"], $_REQUEST["date_end_delyyear"]);
+
+if ($action == 'create') {
+ if (is_array($selected) == false) {
+ $mesgs = array (
+ '' . $langs->trans('Error_OrderNotChecked') . '
'
+ );
+ } else {
+ $origin = GETPOST('origin');
+ $originid = GETPOST('originid');
+ }
+}
+
+// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
+include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
+$hookmanager = new HookManager($db);
+$hookmanager->initHooks(array('orderstoinvoicesupplier'));
+
+/*
+ * Actions
+ */
+
+if (($action == 'create' || $action == 'add') && empty($mesgs)) {
+
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php';
+ if (! empty($conf->projet->enabled))
+ require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
+
+ $langs->load('bills');
+ $langs->load('products');
+ $langs->load('main');
+ if (isset($_GET['orders_to_invoice'])) {
+ $orders_id = $_GET['orders_to_invoice'];
+ $n = count($orders_id);
+ $i = 0;
+
+ $originid = $orders_id[0];
+ $_GET['originid'] = $orders_id[0];
+ }
+ if (isset($_POST['orders_to_invoice'])) {
+ $orders_id = $_POST['orders_to_invoice'];
+ $nn = count($orders_id);
+ $ii = 0;
+
+ $originid = $orders_id[0];
+ $_POST['originid'] = $orders_id[0];
+ }
+
+ $projectid = GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : 0;
+ $lineid = GETPOST('lineid', 'int');
+ $userid = GETPOST('userid', 'int');
+ $search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref') : GETPOST('search_ref');
+
+ // Security check
+ if ($user->societe_id)
+ $socid = $user->societe_id;
+ $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
+
+ $usehm = $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
+ $object = new FactureFournisseur($db);
+
+ // Insert new invoice in database
+ if ($action == 'add' && $user->rights->fournisseur->facture->creer) {
+ $object->socid = GETPOST('socid');
+ $db->begin();
+ $error = 0;
+
+ // Standard or deposit or proforma invoice
+ $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (empty($datefacture)) {
+ $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
+ }
+ if (! $error) {
+ $object->ref = $_POST['ref'];
+ $object->ref_supplier = $_POST['ref_supplier'];
+ $object->socid = $_POST['socid'];
+ $object->libelle = $_POST['libelle'];
+ $object->date = $datefacture;
+ $object->date_echeance = $datedue;
+ $object->note_public = GETPOST('note_public');
+ $object->note_private = GETPOST('note_private');
+ $object->cond_reglement_id = GETPOST('cond_reglement_id');
+ $object->mode_reglement_id = GETPOST('mode_reglement_id');
+ $projectid = GETPOST('projectid');
+ if ($projectid > 0)
+ $object->fk_project = $projectid;
+
+ // Auto calculation of date due if not filled by user
+ if (empty($object->date_echeance))
+ $object->date_echeance = $object->calculate_date_lim_reglement();
+
+ if ($_POST['origin'] && $_POST['originid']) {
+ $object->origin = $_POST['origin'];
+ $object->origin_id = $orders_id[$ii];
+ $object->linked_objects = $orders_id;
+ $id = $object->create($user);
+
+ if ($id > 0) {
+ foreach ( $orders_id as $origin => $origin_id ) {
+ $origin_id = (! empty($origin_id) ? $origin_id : $object->origin_id);
+ $db->begin();
+ $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element (";
+ $sql .= "fk_source";
+ $sql .= ", sourcetype";
+ $sql .= ", fk_target";
+ $sql .= ", targettype";
+ $sql .= ") VALUES (";
+ $sql .= $origin_id;
+ $sql .= ", '" . $object->origin . "'";
+ $sql .= ", " . $id;
+ $sql .= ", '" . $object->element . "'";
+ $sql .= ")";
+
+ if ($db->query($sql)) {
+ $db->commit();
+ } else {
+ $db->rollback();
+ }
+ }
+
+ while ( $ii < $nn ) {
+ $objectsrc = new CommandeFournisseur($db);
+ dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
+ $result = $objectsrc->fetch($orders_id[$ii]);
+ if ($result > 0) {
+ $lines = $objectsrc->lines;
+ if (empty($lines) && method_exists($objectsrc, 'fetch_lines')) {
+ $objectsrc->fetch_lines();
+ $lines = $objectsrc->lines;
+ }
+ $fk_parent_line = 0;
+ $num = count($lines);
+ for($i = 0; $i < $num; $i ++) {
+ $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
+
+ $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
+ $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
+
+ // Dates
+ // TODO mutualiser
+ $date_start = $lines[$i]->date_debut_prevue;
+ if ($lines[$i]->date_debut_reel)
+ $date_start = $lines[$i]->date_debut_reel;
+ if ($lines[$i]->date_start)
+ $date_start = $lines[$i]->date_start;
+ $date_end = $lines[$i]->date_fin_prevue;
+ if ($lines[$i]->date_fin_reel)
+ $date_end = $lines[$i]->date_fin_reel;
+ if ($lines[$i]->date_end)
+ $date_end = $lines[$i]->date_end;
+
+ // Reset fk_parent_line for no child products and special product
+ if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
+ $fk_parent_line = 0;
+ }
+ // FIXME Missing $lines[$i]->ref_supplier and $lines[$i]->label into addline and updateline methods. They are filled when coming from order for example.
+ $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->qty, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, 'HT', $product_type);
+
+ 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;
+ }
+ }
+ } else {
+ $mesgs[] = $objectsrc->error;
+ $error ++;
+ }
+ $ii ++;
+ }
+ } else {
+ $mesgs[] = $object->error;
+ $error ++;
+ }
+ }
+ }
+
+ // End of object creation, we show it
+ if ($id > 0 && ! $error) {
+ $db->commit();
+ header('Location: ' . DOL_URL_ROOT . '/fourn/facture/fiche.php?facid=' . $id);
+ exit();
+ } else {
+ $db->rollback();
+ $action = 'create';
+ $_GET["origin"] = $_POST["origin"];
+ $_GET["originid"] = $_POST["originid"];
+ $mesgs[] = '' . $object->error . '
';
+ }
+ }
+}
+
+/*
+ * View
+ */
+
+$html = new Form($db);
+$htmlother = new FormOther($db);
+$formfile = new FormFile($db);
+$companystatic = new Societe($db);
+
+// Mode creation
+if ($action == 'create' && empty($mesgs)) {
+
+ llxHeader();
+ print_fiche_titre($langs->trans('NewBill'));
+
+ $soc = new Societe($db);
+ if ($socid)
+ $res = $soc->fetch($socid);
+ if ($res) {
+ $cond_reglement_id = $soc->cond_reglement_id;
+ $mode_reglement_id = $soc->mode_reglement_id;
+ }
+ $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : '';
+
+ print '\n";
+
+ print ' ';
+ print "\n";
+}
+
+// Mode liste
+if (($action != 'create' && $action != 'add') || ! empty($mesgs)) {
+ llxHeader();
+ ?>
+
+rights->societe->client->voir && ! $socid)
+ $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
+ $sql .= ' WHERE c.entity = ' . $conf->entity;
+ $sql .= ' AND c.fk_soc = s.rowid';
+
+ // Show orders with status validated, shipping started and delivered (well any order we can bill)
+ $sql .= " AND c.fk_statut IN (5)";
+
+ // Find order that are not already invoiced
+ $sql .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
+
+ if ($socid)
+ $sql .= ' AND s.rowid = ' . $socid;
+ if (! $user->rights->societe->client->voir && ! $socid)
+ $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
+ if ($sref) {
+ $sql .= " AND c.ref LIKE '%" . $db->escape($sref) . "%'";
+ }
+ if ($sall) {
+ $sql .= " AND (c.ref LIKE '%" . $db->escape($sall) . "%' OR c.note LIKE '%" . $db->escape($sall) . "%')";
+ }
+
+ // Date filter
+ if ($date_start && $date_end)
+ $sql .= " AND c.date_commande >= '" . $db->idate($date_start) . "' AND c.date_commande <= '" . $db->idate($date_end) . "'";
+ if ($date_starty && $date_endy)
+ $sql .= " AND c.date_livraison >= '" . $db->idate($date_starty) . "' AND c.date_livraison <= '" . $db->idate($date_endy) . "'";
+
+ if (! empty($sref_client)) {
+ $sql .= ' AND c.ref_supplier LIKE \'%' . $db->escape($sref_client) . '%\'';
+ }
+ $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder;
+ dol_syslog('fourn/commande/ordertoinvoice.php sql=' . $sql);
+ $resql = $db->query($sql);
+
+ if ($resql) {
+ if ($socid) {
+ $soc = new Societe($db);
+ $soc->fetch($socid);
+ }
+ $title = $langs->trans('ListOfSupplierOrders');
+ $title .= ' - ' . $langs->trans('StatusOrderReceivedAllShort');
+ $num = $db->num_rows($resql);
+ print_fiche_titre($title);
+ $i = 0;
+ $period = $html->select_date($date_start, 'date_start', 0, 0, 1, '', 1, 0, 1) . ' - ' . $html->select_date($date_end, 'date_end', 0, 0, 1, '', 1, 0, 1);
+ $periodely = $html->select_date($date_starty, 'date_start_dely', 0, 0, 1, '', 1, 0, 1) . ' - ' . $html->select_date($date_endy, 'date_end_dely', 0, 0, 1, '', 1, 0, 1);
+
+ if (! empty($socid)) {
+ // Company
+ $companystatic->id = $socid;
+ $companystatic->nom = $soc->nom;
+ print '
' . $companystatic->getNomUrl(1, 'customer') . ' ';
+ }
+
+ print '
';
+ print '';
+ print_liste_field_titre($langs->trans('Ref'), 'orderstoinvoice.php', 'c.ref', '', '&socid=' . $socid, '', $sortfield, $sortorder);
+ print_liste_field_titre($langs->trans('RefSupplier'), 'orderstoinvoice.php', 'c.ref_supplier', '', '&socid=' . $socid, '', $sortfield, $sortorder);
+ print_liste_field_titre($langs->trans('OrderDate'), 'orderstoinvoice.php', 'c.date_commande', '', '&socid=' . $socid, 'align="center"', $sortfield, $sortorder);
+ print_liste_field_titre($langs->trans('DeliveryDate'), 'orderstoinvoice.php', 'c.date_livraison', '', '&socid=' . $socid, 'align="center"', $sortfield, $sortorder);
+ print_liste_field_titre($langs->trans('Status'), '', '', '', '', 'align="right"');
+ print_liste_field_titre($langs->trans('GenerateBill'), '', '', '', '', 'align="center"');
+ print ' ';
+
+ // Lignes des champs de filtre
+ print '';
+ print ' ';
+ print '';
+ print '';
+ // REF
+ print ' ';
+ print ' ';
+ // print '';
+ print ' ';
+ print ' ';
+
+ // DATE ORDER
+ print ' ';
+ print $period;
+ print ' ';
+
+ // DATE DELIVERY
+ print '';
+ print $periodely;
+ print ' ';
+
+ // SEARCH BUTTON
+ print '';
+ print ' ';
+
+ // ALL/NONE
+ print ' ';
+ if ($conf->use_javascript_ajax)
+ print '' . $langs->trans("All") . ' / ' . $langs->trans("None") . ' ';
+ print ' ';
+
+ print ' ';
+ print ' ';
+
+ print '';
+ $var = True;
+ $generic_commande = new CommandeFournisseur($db);
+
+ while ( $i < $num ) {
+ $objp = $db->fetch_object($resql);
+ $var = ! $var;
+ print '';
+ print '';
+
+ $generic_commande->id = $objp->rowid;
+ $generic_commande->ref = $objp->ref;
+
+ print '';
+ print '';
+ print $generic_commande->getNomUrl(1, $objp->fk_statut);
+ print ' ';
+
+ print '';
+ $filename = dol_sanitizeFileName($objp->ref);
+ $filedir = $conf->fournisseur->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref);
+ $urlsource = $_SERVER['PHP_SELF'] . '?id=' . $objp->rowid;
+ print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
+ print '
';
+ print ' ';
+
+ print '' . $objp->ref_supplier . ' ';
+
+ // Order date
+ print '';
+ print dol_print_date($db->jdate($objp->date_commande), 'day');
+ print ' ';
+
+ // Delivery date
+ print '';
+ print dol_print_date($db->jdate($objp->date_livraison), 'day');
+ print ' ';
+
+ // Statut
+ print '' . $generic_commande->LibStatut($objp->fk_statut, 5) . ' ';
+
+ // Checkbox
+ print '';
+ print ' ';
+ print ' ';
+
+ print ' ';
+
+ $total = $total + $objp->price;
+ $subtotal = $subtotal + $objp->price;
+ $i ++;
+ }
+ print '
';
+
+ /*
+ * Boutons actions
+ */
+ print '
';
+ print '';
+ print '';
+ $db->free($resql);
+ } else {
+ print dol_print_error($db);
+ }
+}
+
+dol_htmloutput_mesg($mesg, $mesgs);
+
+llxFooter();
+$db->close();
diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
index 778b3f2b9ff..c3e494c92c0 100644
--- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
+++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
@@ -47,9 +47,9 @@ ALTER TABLE llx_user ADD COLUMN fk_user_modif integer AFTER fk_user_creat;
-- Add module accounting Expert
ALTER TABLE llx_bookkeeping RENAME TO llx_accounting_bookkeeping; -- To update old user of module Accounting Expert
-
-CREATE TABLE llx_accounting_bookkeeping
+
+CREATE TABLE llx_accounting_bookkeeping
(
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
doc_date date NOT NULL,
@@ -79,7 +79,7 @@ ALTER TABLE llx_accountingaccount add column tms timestamp AFTER datec;
ALTER TABLE llx_accountingaccount add column fk_user_author integer DEFAULT NULL AFTER label;
ALTER TABLE llx_accountingaccount add column fk_user_modif integer DEFAULT NULL AFTER fk_user_author;
--- Qual
+-- Qual
UPDATE llx_const SET name = 'ACCOUNTING_MODE' WHERE name = 'COMPTA_MODE';
UPDATE llx_const SET name = 'ACCOUNTING_ACCOUNT_CUSTOMER' WHERE name = 'COMPTA_ACCOUNT_CUSTOMER';
UPDATE llx_const SET name = 'ACCOUNTING_ACCOUNT_SUPPLIER' WHERE name = 'COMPTA_ACCOUNT_SUPPLIER';
@@ -204,7 +204,7 @@ create table llx_accounting_fiscalyear
)ENGINE=innodb;
ALTER TABLE llx_contrat ADD COLUMN ref_ext varchar(30) after ref;
-ALTER TABLE llx_contrat ADD COLUMN ref_customer varchar(30) after ref_ext;
+ALTER TABLE llx_contrat ADD COLUMN ref_supplier varchar(30) after ref_ext;
ALTER TABLE llx_propal ADD COLUMN fk_shipping_method integer AFTER date_livraison;
ALTER TABLE llx_commande ADD COLUMN fk_shipping_method integer AFTER date_livraison;
diff --git a/htdocs/langs/en_US/suppliers.lang b/htdocs/langs/en_US/suppliers.lang
index fdc0787646a..50502c15c7e 100644
--- a/htdocs/langs/en_US/suppliers.lang
+++ b/htdocs/langs/en_US/suppliers.lang
@@ -40,3 +40,5 @@ AddSupplierInvoice=Create supplier invoice
ListOfSupplierProductForSupplier=List of products and prices for supplier %s
NoneOrBatchFileNeverRan=None or batch %s not ran recently
SentToSuppliers=Sent to suppliers
+ListOfSupplierOrders=List of supplier orders
+MenuOrdersSupplierToBill=Supplier orders to invoice
\ No newline at end of file
diff --git a/htdocs/langs/fr_FR/suppliers.lang b/htdocs/langs/fr_FR/suppliers.lang
index 8e0f3475db4..f558b0779ea 100644
--- a/htdocs/langs/fr_FR/suppliers.lang
+++ b/htdocs/langs/fr_FR/suppliers.lang
@@ -40,3 +40,5 @@ AddSupplierInvoice=Créer facture fournisseur
ListOfSupplierProductForSupplier=Liste des produits et prix du fournisseurs %s
NoneOrBatchFileNeverRan=Aucun ou traitement par lot %s non exécuté récemment
SentToSuppliers=Envoyés aux fournisseurs
+ListOfSupplierOrders=Liste des commandes fournisseur
+MenuOrdersSupplierToBill=Commandes fournisseur à facturer
\ No newline at end of file