2012-05-30 14:48:23 +02:00
< ? php
/* Copyright ( C ) 2001 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2013-09-16 11:50:53 +02:00
* Copyright ( C ) 2004 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-05-30 14:48:23 +02:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-05-30 14:48:23 +02:00
* Copyright ( C ) 2012 Andreu Bisquerra Gaya < jove @ bisquerra . com >
* Copyright ( C ) 2012 David Rodriguez Martinez < davidrm146 @ gmail . com >
2018-05-17 18:56:01 +02:00
* Copyright ( C ) 2012 - 2018 Juanjo Menent < jmenent @ 2 byte . es >
2015-11-18 17:56:04 +01:00
* Copyright ( C ) 2015 Ferran Marcet < fmarcet @ 2 byte . es >
2012-05-30 14:48:23 +02:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-05-30 14:48:23 +02:00
* ( 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 < http :// www . gnu . org / licenses />.
*/
/**
* \file htdocs / commande / orderstoinvoice . php
* \ingroup commande
* \brief Page to invoice multiple orders
*/
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2013-04-14 13:06:13 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2012-08-22 23:11:24 +02:00
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' ;
2013-06-14 22:33:01 +02:00
if ( ! empty ( $conf -> projet -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
}
2012-05-30 14:48:23 +02:00
2018-05-26 18:41:16 +02:00
// Load translation files required by the page
2018-05-24 10:48:03 +02:00
$langs -> loadLangs ( array ( " orders " , " deliveries " , " companies " ));
2012-05-30 14:48:23 +02:00
2012-09-30 21:26:58 +02:00
if ( ! $user -> rights -> facture -> creer )
2012-05-30 14:48:23 +02:00
accessforbidden ();
2016-12-18 01:44:26 +01:00
$id = ( GETPOST ( 'id' ) ? GETPOST ( 'id' , 'int' ) : GETPOST ( " facid " , " int " )); // For backward compatibility
2012-09-30 21:26:58 +02:00
$ref = GETPOST ( 'ref' , 'alpha' );
$action = GETPOST ( 'action' , 'alpha' );
2012-09-21 08:23:48 +02:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
$sref = GETPOST ( 'sref' );
$sref_client = GETPOST ( 'sref_client' );
2017-12-12 11:31:30 +01:00
$sall = trim (( GETPOST ( 'search_all' , 'alphanohtml' ) != '' ) ? GETPOST ( 'search_all' , 'alphanohtml' ) : GETPOST ( 'sall' , 'alphanohtml' ));
2012-09-21 08:23:48 +02:00
$socid = GETPOST ( 'socid' , 'int' );
2013-04-07 21:58:24 +02:00
$selected = GETPOST ( 'orders_to_invoice' );
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$viewstatut = GETPOST ( 'viewstatut' );
2012-09-21 08:23:48 +02:00
2014-07-20 01:09:43 +02:00
$error = 0 ;
2012-05-30 14:48:23 +02:00
if ( ! $sortfield ) $sortfield = 'c.rowid' ;
if ( ! $sortorder ) $sortorder = 'DESC' ;
2012-06-06 18:02:47 +02:00
2013-04-07 21:58:24 +02:00
$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 " ]);
2016-07-05 16:41:46 +02:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
$extralabels = $extrafields -> fetch_name_optionals_label ( 'facture' );
2012-05-30 14:48:23 +02:00
if ( $action == 'create' )
{
2016-06-28 02:40:42 +02:00
if ( ! is_array ( $selected ))
2012-05-30 14:48:23 +02:00
{
2014-07-20 01:09:43 +02:00
$error ++ ;
2015-11-10 19:22:27 +01:00
setEventMessages ( $langs -> trans ( 'Error_OrderNotChecked' ), null , 'errors' );
2012-05-30 14:48:23 +02:00
}
else
{
2013-04-07 21:58:24 +02:00
$origin = GETPOST ( 'origin' );
$originid = GETPOST ( 'originid' );
2012-05-30 14:48:23 +02:00
}
}
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2013-05-29 13:28:44 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
$hookmanager = new HookManager ( $db );
$hookmanager -> initHooks ( array ( 'orderstoinvoice' ));
2012-07-02 19:30:37 +02:00
/*
* Actions
2012-07-23 21:31:10 +02:00
*/
2012-05-30 14:48:23 +02:00
2014-07-20 01:09:43 +02:00
if (( $action == 'create' || $action == 'add' ) && ! $error )
2012-05-30 14:48:23 +02:00
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php' ;
2013-09-16 11:50:53 +02:00
if ( ! empty ( $conf -> projet -> enabled )) require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2014-09-04 18:58:33 +02:00
2012-07-02 19:30:37 +02:00
$langs -> load ( 'bills' );
$langs -> load ( 'products' );
$langs -> load ( 'main' );
if ( isset ( $_GET [ 'orders_to_invoice' ]))
{
2016-12-18 01:44:26 +01:00
$orders_id = GETPOST ( 'orders_to_invoice' , '' , 1 );
2012-07-02 19:30:37 +02:00
$n = count ( $orders_id );
$i = 0 ;
$originid = $orders_id [ 0 ];
$_GET [ 'originid' ] = $orders_id [ 0 ];
}
if ( isset ( $_POST [ 'orders_to_invoice' ]))
{
2017-03-17 17:05:59 +01:00
$orders_id = GETPOST ( 'orders_to_invoice' , '' , 2 );
2012-07-02 19:30:37 +02:00
$nn = count ( $orders_id );
$ii = 0 ;
$originid = $orders_id [ 0 ];
$_POST [ 'originid' ] = $orders_id [ 0 ];
}
2012-09-21 08:23:48 +02:00
$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' );
2013-09-16 11:50:53 +02:00
$closeOrders = GETPOST ( 'autocloseorders' ) ? true : false ;
2012-07-02 19:30:37 +02:00
// Security check
2012-09-21 08:23:48 +02:00
$fieldid = GETPOST ( 'ref' , 'alpha' ) ? 'facnumber' : 'rowid' ;
2012-07-02 19:30:37 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'facture' , $id , '' , '' , 'fk_soc' , $fieldid );
$usehm = $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ;
2012-05-30 14:48:23 +02:00
$object = new Facture ( $db );
2012-07-02 19:30:37 +02:00
// Insert new invoice in database
if ( $action == 'add' && $user -> rights -> facture -> creer )
{
$object -> socid = GETPOST ( 'socid' );
$db -> begin ();
2012-05-31 21:25:22 +02:00
$error = 0 ;
2012-07-02 19:30:37 +02:00
// Standard or deposit or proforma invoice
if ( $_POST [ 'type' ] == 0 )
{
$datefacture = dol_mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
if ( empty ( $datefacture ))
{
2012-10-03 11:53:14 +02:00
$datefacture = dol_mktime ( date ( " h " ), date ( " M " ), 0 , date ( " m " ), date ( " d " ), date ( " Y " ));
2012-07-02 19:30:37 +02:00
}
if ( ! $error )
{
// Si facture standard
$object -> socid = $_POST [ 'socid' ];
$object -> type = $_POST [ 'type' ];
$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 = ( $_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' ];
2016-07-05 16:41:46 +02:00
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object );
if ( $ret < 0 ) $error ++ ;
2012-07-02 19:30:37 +02:00
if ( $_POST [ 'origin' ] && $_POST [ 'originid' ])
2012-05-30 14:48:23 +02:00
{
$object -> origin = $_POST [ 'origin' ];
$object -> origin_id = $orders_id [ $ii ];
2012-07-02 19:30:37 +02:00
$object -> linked_objects = $orders_id ;
2012-05-30 14:48:23 +02:00
$id = $object -> create ( $user );
2015-11-18 17:56:04 +01:00
$object -> fetch_thirdparty ();
2012-05-31 21:25:22 +02:00
2012-05-30 14:48:23 +02:00
if ( $id > 0 )
{
foreach ( $orders_id as $origin => $origin_id )
2012-07-02 19:30:37 +02:00
{
$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 ();
2012-05-30 14:48:23 +02:00
}
2012-07-02 19:30:37 +02:00
else
{
$db -> rollback ();
}
}
while ( $ii < $nn )
{
2013-05-29 13:28:44 +02:00
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
$objectsrc = new Commande ( $db );
2012-07-02 19:30:37 +02:00
dol_syslog ( " Try to find source object origin= " . $object -> origin . " originid= " . $object -> origin_id . " to add lines " );
2013-05-29 13:28:44 +02:00
$result = $objectsrc -> fetch ( $orders_id [ $ii ]);
2012-07-02 19:30:37 +02:00
if ( $result > 0 )
2012-05-30 14:48:23 +02:00
{
2014-09-04 18:58:33 +02:00
if ( $closeOrders )
2013-09-16 11:50:53 +02:00
{
2016-04-09 18:50:22 +02:00
$objectsrc -> classifyBilled ( $user );
2013-05-29 13:28:44 +02:00
$objectsrc -> setStatut ( 3 );
2012-09-23 18:00:30 +02:00
}
2013-05-29 13:28:44 +02:00
$lines = $objectsrc -> lines ;
2014-09-04 18:58:33 +02:00
if ( empty ( $lines ) && method_exists ( $objectsrc , 'fetch_lines' ))
{
$objectsrc -> fetch_lines ();
$lines = $objectsrc -> lines ;
}
2012-07-02 19:30:37 +02:00
$fk_parent_line = 0 ;
$num = count ( $lines );
for ( $i = 0 ; $i < $num ; $i ++ )
{
$desc = ( $lines [ $i ] -> desc ? $lines [ $i ] -> desc : $lines [ $i ] -> libelle );
if ( $lines [ $i ] -> subprice < 0 )
{
// Negative line, we create a discount line
$discount = new DiscountAbsolute ( $db );
$discount -> fk_soc = $object -> socid ;
$discount -> amount_ht = abs ( $lines [ $i ] -> total_ht );
$discount -> amount_tva = abs ( $lines [ $i ] -> total_tva );
$discount -> amount_ttc = abs ( $lines [ $i ] -> total_ttc );
$discount -> tva_tx = $lines [ $i ] -> tva_tx ;
$discount -> fk_user = $user -> id ;
$discount -> description = $desc ;
$discountid = $discount -> create ( $user );
if ( $discountid > 0 )
{
$result = $object -> insert_discount ( $discountid );
//$result=$discount->link_to_invoice($lineid,$id);
}
else
{
2015-11-10 19:22:27 +01:00
setEventMessages ( $discount -> error , $discount -> errors , 'errors' );
2012-07-02 19:30:37 +02:00
$error ++ ;
break ;
}
}
else
{
// Positive line
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : 0 );
// Date start
$date_start = false ;
if ( $lines [ $i ] -> date_debut_prevue ) $date_start = $lines [ $i ] -> date_debut_prevue ;
if ( $lines [ $i ] -> date_debut_reel ) $date_start = $lines [ $i ] -> date_debut_reel ;
if ( $lines [ $i ] -> date_start ) $date_start = $lines [ $i ] -> date_start ;
//Date end
$date_end = false ;
if ( $lines [ $i ] -> date_fin_prevue ) $date_end = $lines [ $i ] -> date_fin_prevue ;
if ( $lines [ $i ] -> date_fin_reel ) $date_end = $lines [ $i ] -> date_fin_reel ;
if ( $lines [ $i ] -> date_end ) $date_end = $lines [ $i ] -> date_end ;
// Reset fk_parent_line for no child products and special product
2012-05-31 21:25:22 +02:00
if (( $lines [ $i ] -> product_type != 9 && empty ( $lines [ $i ] -> fk_parent_line )) || $lines [ $i ] -> product_type == 9 )
2012-07-02 19:30:37 +02:00
{
$fk_parent_line = 0 ;
}
2018-05-17 18:56:01 +02:00
// Extrafields
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED ) && method_exists ( $lines [ $i ], 'fetch_optionals' )) {
$lines [ $i ] -> fetch_optionals ( $lines [ $i ] -> rowid );
$array_options = $lines [ $i ] -> array_options ;
}
2012-08-07 13:12:20 +02:00
$result = $object -> addline (
$desc ,
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$lines [ $i ] -> tva_tx ,
$lines [ $i ] -> localtax1_tx ,
$lines [ $i ] -> localtax2_tx ,
$lines [ $i ] -> fk_product ,
$lines [ $i ] -> remise_percent ,
$date_start ,
$date_end ,
0 ,
$lines [ $i ] -> info_bits ,
$lines [ $i ] -> fk_remise_except ,
'HT' ,
0 ,
$product_type ,
2014-07-08 09:00:41 +02:00
$ii ,
2012-08-07 13:12:20 +02:00
$lines [ $i ] -> special_code ,
$object -> origin ,
$lines [ $i ] -> rowid ,
2013-04-14 13:06:13 +02:00
$fk_parent_line ,
$lines [ $i ] -> fk_fournprice ,
2016-01-28 11:42:00 +01:00
$lines [ $i ] -> pa_ht ,
2018-05-17 18:56:01 +02:00
$lines [ $i ] -> label ,
$array_options
2012-08-07 13:12:20 +02:00
);
2012-07-02 19:30:37 +02:00
if ( $result > 0 )
{
$lineid = $result ;
}
else
{
$lineid = 0 ;
$error ++ ;
break ;
}
// Defined the new fk_parent_line
2012-05-31 21:25:22 +02:00
if ( $result > 0 && $lines [ $i ] -> product_type == 9 )
2012-07-02 19:30:37 +02:00
{
$fk_parent_line = $result ;
}
}
}
2012-05-30 14:48:23 +02:00
}
2012-07-02 19:30:37 +02:00
else
{
2015-11-10 19:22:27 +01:00
setEventMessages ( $objectsrc -> error , $objectsrc -> errors , 'errors' );
2012-07-02 19:30:37 +02:00
$error ++ ;
}
$ii ++ ;
2012-05-31 21:25:22 +02:00
}
2012-05-30 14:48:23 +02:00
}
2012-07-02 19:30:37 +02:00
else
{
2015-11-10 19:22:27 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2012-07-02 19:30:37 +02:00
$error ++ ;
}
}
2012-05-30 14:48:23 +02:00
}
}
2012-07-02 19:30:37 +02:00
// End of object creation, we show it
if ( $id > 0 && ! $error )
{
$db -> commit ();
2017-03-20 20:58:43 +01:00
header ( 'Location: ' . DOL_URL_ROOT . '/compta/facture/card.php?facid=' . $id );
2012-07-02 19:30:37 +02:00
exit ;
}
else
{
$db -> rollback ();
$action = 'create' ;
$_GET [ " origin " ] = $_POST [ " origin " ];
$_GET [ " originid " ] = $_POST [ " originid " ];
2015-11-10 19:22:27 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-07-20 01:09:43 +02:00
$error ++ ;
2012-07-02 19:30:37 +02:00
}
2012-05-30 14:48:23 +02:00
}
2012-08-07 13:12:20 +02:00
}
2012-07-02 19:30:37 +02:00
2012-08-07 13:12:20 +02:00
/*
* View
*/
2012-07-23 21:31:10 +02:00
2012-08-07 13:12:20 +02:00
$html = new Form ( $db );
$htmlother = new FormOther ( $db );
$formfile = new FormFile ( $db );
$companystatic = new Societe ( $db );
2012-07-23 21:31:10 +02:00
2012-08-07 13:12:20 +02:00
// Mode creation
2014-07-20 01:09:43 +02:00
if ( $action == 'create' && ! $error )
2012-08-07 13:12:20 +02:00
{
$facturestatic = new Facture ( $db );
llxHeader ();
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( 'NewBill' ));
2012-08-07 13:12:20 +02:00
$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 ;
$remise_percent = $soc -> remise_percent ;
}
$remise_absolue = 0 ;
2014-05-25 14:51:56 +02:00
$dateinvoice = empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : '' ;
2012-08-07 13:12:20 +02:00
$absolute_discount = $soc -> getAvailableDiscounts ();
print '<form name="add" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' . " \n " ;
print '<input name="facnumber" type="hidden" value="provisoire">' ;
print '<input name="ref_client" type="hidden" value="' . $ref_client . '">' ;
print '<input name="ref_int" type="hidden" value="' . $ref_int . '">' ;
print '<input type="hidden" name="origin" value="' . GETPOST ( 'origin' ) . '">' ;
print '<input type="hidden" name="originid" value="' . GETPOST ( 'originid' ) . '">' ;
2012-09-23 18:00:30 +02:00
print '<input type="hidden" name="autocloseorders" value="' . GETPOST ( 'autocloseorders' ) . '">' ;
2016-01-28 11:42:00 +01:00
2015-09-03 11:00:53 +02:00
dol_fiche_head ();
2016-01-28 11:42:00 +01:00
2012-08-07 13:12:20 +02:00
print '<table class="border" width="100%">' ;
2012-10-03 11:53:14 +02:00
2012-08-07 13:12:20 +02:00
// Ref
2017-06-07 16:44:04 +02:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Ref' ) . '</td><td>' . $langs -> trans ( 'Draft' ) . '</td></tr>' ;
2012-10-03 11:53:14 +02:00
// Third party
2017-06-07 16:44:04 +02:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Customer' ) . '</td><td>' ;
2012-08-07 13:12:20 +02:00
print $soc -> getNomUrl ( 1 );
print '<input type="hidden" name="socid" value="' . $soc -> id . '">' ;
print '</td>' ;
print '</tr>' . " \n " ;
2012-10-03 11:53:14 +02:00
// Type
2017-06-07 16:44:04 +02:00
print '<tr><td class="tdtop fieldrequired">' . $langs -> trans ( 'Type' ) . '</td><td>' ;
2012-08-07 13:12:20 +02:00
print '<table class="nobordernopadding">' . " \n " ;
2012-10-03 11:53:14 +02:00
2012-08-07 13:12:20 +02:00
// Standard invoice
print '<tr height="18"><td width="16px" valign="middle">' ;
2015-05-07 11:39:26 +02:00
print '<input type="radio" name="type" value="0"' . ( GETPOST ( 'type' ) == 0 ? ' checked' : '' ) . '>' ;
2012-08-07 13:12:20 +02:00
print '</td><td valign="middle">' ;
2016-03-25 15:24:57 +01:00
$desc = $html -> textwithpicto ( $langs -> trans ( " InvoiceStandardAsk " ), $langs -> transnoentities ( " InvoiceStandardDesc " ), 1 );
2012-08-07 13:12:20 +02:00
print $desc ;
print '</td></tr>' . " \n " ;
print '</table>' ;
2012-10-01 21:53:22 +02:00
2012-08-07 13:12:20 +02:00
// Date invoice
2017-06-07 16:44:04 +02:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Date' ) . '</td><td>' ;
2016-03-25 15:53:44 +01:00
$html -> select_date ( '' , '' , '' , '' , '' , " add " , 1 , 1 );
2012-08-07 13:12:20 +02:00
print '</td></tr>' ;
// Payment term
2017-06-07 16:44:04 +02:00
print '<tr><td class="nowrap">' . $langs -> trans ( 'PaymentConditionsShort' ) . '</td><td>' ;
2012-08-07 13:12:20 +02:00
$html -> select_conditions_paiements ( isset ( $_POST [ 'cond_reglement_id' ]) ? $_POST [ 'cond_reglement_id' ] : $cond_reglement_id , 'cond_reglement_id' );
print '</td></tr>' ;
// Payment mode
2017-06-07 16:44:04 +02:00
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td>' ;
2012-08-07 13:12:20 +02:00
$html -> select_types_paiements ( isset ( $_POST [ 'mode_reglement_id' ]) ? $_POST [ 'mode_reglement_id' ] : $mode_reglement_id , 'mode_reglement_id' );
print '</td></tr>' ;
// Project
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> projet -> enabled ))
2012-08-07 13:12:20 +02:00
{
2013-06-14 22:33:01 +02:00
$formproject = new FormProjets ( $db );
2013-07-10 17:29:54 +02:00
2012-08-07 13:12:20 +02:00
$langs -> load ( 'projects' );
2017-06-07 16:44:04 +02:00
print '<tr><td>' . $langs -> trans ( 'Project' ) . '</td><td>' ;
2013-06-14 22:33:01 +02:00
$formproject -> select_projects ( $soc -> id , $projectid , 'projectid' );
2012-07-02 19:30:37 +02:00
print '</td></tr>' ;
2012-08-07 13:12:20 +02:00
}
2013-05-29 13:28:44 +02:00
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
$objectsrc = new Commande ( $db );
$listoforders = array ();
foreach ( $selected as $sel )
{
$result = $objectsrc -> fetch ( $sel );
if ( $result > 0 )
{
$listoforders [] = $objectsrc -> ref ;
}
}
// Other attributes
2017-06-07 16:44:04 +02:00
$parameters = array ( 'objectsrc' => $objectsrc , 'idsrc' => $listoforders );
2013-05-29 13:28:44 +02:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2017-06-11 10:37:58 +02:00
print $hookmanager -> resPrint ;
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook ))
2016-07-05 16:41:46 +02:00
{
$object = new Facture ( $db );
print $object -> showOptionals ( $extrafields , 'edit' );
}
2012-08-07 13:12:20 +02:00
// Modele PDF
print '<tr><td>' . $langs -> trans ( 'Model' ) . '</td>' ;
print '<td>' ;
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php' ;
2012-08-07 13:12:20 +02:00
$liste = ModelePDFFactures :: liste_modeles ( $db );
2016-03-25 15:34:37 +01:00
print $html -> selectarray ( 'model' , $liste , $conf -> global -> FACTURE_ADDON_PDF );
2012-08-07 13:12:20 +02:00
print " </td></tr> " ;
// Public note
print '<tr>' ;
print '<td class="border" valign="top">' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
2017-06-07 16:44:04 +02:00
print '<td valign="top">' ;
print '<textarea name="note_public" class="quatrevingtpercent" rows="' . ROWS_3 . '">' ;
2012-08-07 13:12:20 +02:00
2013-05-29 13:28:44 +02:00
print $langs -> trans ( " Orders " ) . " : " . implode ( ', ' , $listoforders );
2012-08-07 13:12:20 +02:00
print '</textarea></td></tr>' ;
// Private note
2014-02-27 10:37:23 +01:00
if ( empty ( $user -> societe_id ))
2012-08-07 13:12:20 +02:00
{
2012-07-02 19:30:37 +02:00
print '<tr>' ;
2012-08-07 13:12:20 +02:00
print '<td class="border" valign="top">' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
2017-06-07 16:44:04 +02:00
print '<td valign="top">' ;
print '<textarea name="note" class="quatrevingtpercent" rows="' . ROWS_3 . '">' ;
2012-07-02 19:30:37 +02:00
print '</textarea></td></tr>' ;
2012-08-07 13:12:20 +02:00
}
2012-07-02 19:30:37 +02:00
2012-08-07 13:12:20 +02:00
print '</table>' ;
2012-05-31 21:25:22 +02:00
2012-07-02 19:30:37 +02:00
while ( $i < $n )
{
print '<input type="hidden" name="orders_to_invoice[]" value="' . $orders_id [ $i ] . '">' ;
2012-09-15 09:02:20 +02:00
2012-07-02 19:30:37 +02:00
$i ++ ;
2012-05-30 14:48:23 +02:00
}
2012-09-15 09:02:20 +02:00
2015-09-03 11:00:53 +02:00
dol_fiche_end ();
2016-01-28 11:42:00 +01:00
2012-07-02 19:30:37 +02:00
// Button "Create Draft"
2015-09-03 11:00:53 +02:00
print '<div class="center"><input type="submit" class="button" name="bouton" value="' . $langs -> trans ( 'CreateDraft' ) . '" /></div>' ;
2012-05-30 14:48:23 +02:00
print " </form> \n " ;
2012-10-01 21:53:22 +02:00
2012-09-23 18:00:30 +02:00
print '</td></tr>' ;
print " </table> \n " ;
2016-01-28 11:42:00 +01:00
2012-05-30 14:48:23 +02:00
}
2015-09-03 11:00:53 +02:00
// Mode liste
if (( $action != 'create' && $action != 'add' ) || ( $action == 'create' && $error ))
2012-05-31 21:25:22 +02:00
{
2012-05-30 14:48:23 +02:00
llxHeader ();
?>
2012-08-07 13:12:20 +02:00
< script type = " text/javascript " >
2012-05-30 14:48:23 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( " #checkall " ) . click ( function () {
2015-05-12 14:22:00 +02:00
jQuery ( " .checkformerge " ) . prop ( 'checked' , true );
2012-05-30 14:48:23 +02:00
});
jQuery ( " #checknone " ) . click ( function () {
2015-05-12 14:22:00 +02:00
jQuery ( " .checkformerge " ) . prop ( 'checked' , false );
2012-05-30 14:48:23 +02:00
});
});
</ script >
2012-05-31 21:25:22 +02:00
< ? php
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
$sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,' ;
2018-03-16 10:51:12 +01:00
$sql .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed' ;
2012-05-30 14:48:23 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
$sql .= ', ' . MAIN_DB_PREFIX . 'commande as c' ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2017-05-30 18:50:54 +02:00
$sql .= ' WHERE c.entity IN (' . getEntity ( 'commande' ) . ')' ;
2012-09-21 08:23:48 +02:00
$sql .= ' AND c.fk_soc = s.rowid' ;
2012-09-21 09:33:12 +02:00
// Show orders with status validated, shipping started and delivered (well any order we can bill)
$sql .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0)) " ;
2012-09-21 08:23:48 +02:00
2012-05-30 14:48:23 +02:00
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 ) . " %') " ;
}
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
//Date filter
if ( $date_start && $date_end ) $sql .= " AND c.date_commande >= ' " . $db -> idate ( $date_start ) . " ' AND c.date_commande <= ' " . $db -> idate ( $date_end ) . " ' " ;
2012-07-02 19:30:37 +02:00
if ( $date_starty && $date_endy ) $sql .= " AND c.date_livraison >= ' " . $db -> idate ( $date_starty ) . " ' AND c.date_livraison <= ' " . $db -> idate ( $date_endy ) . " ' " ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
if ( ! empty ( $sref_client ))
{
$sql .= ' AND c.ref_client LIKE \'%' . $db -> escape ( $sref_client ) . '%\'' ;
}
$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder ;
$resql = $db -> query ( $sql );
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
if ( $resql )
{
if ( $socid )
{
$soc = new Societe ( $db );
$soc -> fetch ( $socid );
}
2012-10-03 11:43:39 +02:00
$title = $langs -> trans ( 'ListOfOrders' );
2012-09-21 09:33:12 +02:00
$title .= ' - ' . $langs -> trans ( 'StatusOrderValidated' ) . ', ' . $langs -> trans ( " StatusOrderSent " ) . ', ' . $langs -> trans ( 'StatusOrderToBill' );
2012-05-30 14:48:23 +02:00
$num = $db -> num_rows ( $resql );
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $title );
2012-05-30 14:48:23 +02:00
$i = 0 ;
2016-03-25 15:53:44 +01:00
$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 );
2012-09-15 09:02:20 +02:00
2012-09-21 08:23:48 +02:00
if ( ! empty ( $socid ))
{
// Company
$companystatic -> id = $socid ;
2014-10-04 17:20:17 +02:00
$companystatic -> name = $soc -> name ;
2012-09-21 08:23:48 +02:00
print '<h3>' . $companystatic -> getNomUrl ( 1 , 'customer' ) . '</h3>' ;
}
2012-05-30 14:48:23 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( 'Ref' , $_SERVER [ " PHP_SELF " ], 'c.ref' , '' , '&socid=' . $socid , '' , $sortfield , $sortorder );
print_liste_field_titre ( 'RefCustomerOrder' , $_SERVER [ " PHP_SELF " ], 'c.ref_client' , '' , '&socid=' . $socid , '' , $sortfield , $sortorder );
print_liste_field_titre ( 'OrderDate' , $_SERVER [ " PHP_SELF " ], 'c.date_commande' , '' , '&socid=' . $socid , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( 'DeliveryDate' , $_SERVER [ " PHP_SELF " ], 'c.date_livraison' , '' , '&socid=' . $socid , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( 'Status' , '' , '' , '' , '' , 'align="right"' );
print_liste_field_titre ( 'GenerateBill' , '' , '' , '' , '' , 'align="center"' );
2012-05-30 14:48:23 +02:00
print '</tr>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
// Lignes des champs de filtre
print '<form method="get" action="orderstoinvoice.php">' ;
print '<input type="hidden" name="socid" value="' . $socid . '">' ;
print '<tr class="liste_titre">' ;
print '<td class="liste_titre">' ;
//REF
print '<input class="flat" size="10" type="text" name="sref" value="' . $sref . '">' ;
print '</td>' ;
2016-03-08 17:31:46 +01:00
2012-05-30 14:48:23 +02:00
print '<td class="liste_titre" align="left">' ;
print '<input class="flat" type="text" size="10" name="sref_client" value="' . $sref_client . '">' ;
2016-03-08 17:31:46 +01:00
print '</td>' ;
2017-06-07 16:44:04 +02:00
2012-05-30 14:48:23 +02:00
//DATE ORDER
print '<td class="liste_titre" align="center">' ;
print $period ;
2012-08-07 13:12:20 +02:00
print '</td>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
//DATE DELIVERY
print '<td class="liste_titre" align="center">' ;
print $periodely ;
print '</td>' ;
2012-09-15 09:02:20 +02:00
2012-08-07 13:12:20 +02:00
//SEARCH BUTTON
2016-03-08 17:31:46 +01:00
print '<td align="right" class="liste_titre">' ;
2014-01-13 09:43:21 +01:00
print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto ( $langs -> trans ( " Search " ), 'search.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
2016-03-08 17:31:46 +01:00
print '</td>' ;
2017-06-07 16:44:04 +02:00
2012-05-30 14:48:23 +02:00
//ALL/NONE
2016-03-08 17:31:46 +01:00
print '<td align="center" class="liste_titre">' ;
2012-07-02 19:30:37 +02:00
if ( $conf -> use_javascript_ajax ) print '<a href="#" id="checkall">' . $langs -> trans ( " All " ) . '</a> / <a href="#" id="checknone">' . $langs -> trans ( " None " ) . '</a>' ;
2012-05-30 14:48:23 +02:00
print '</td>' ;
2012-09-15 09:02:20 +02:00
2016-03-08 17:31:46 +01:00
print '</tr>' ;
2012-05-30 14:48:23 +02:00
print '</form>' ;
2012-09-15 09:02:20 +02:00
2012-05-31 21:25:22 +02:00
print '<form name="orders2invoice" action="orderstoinvoice.php" method="GET">' ;
2018-05-24 10:48:03 +02:00
2012-05-30 14:48:23 +02:00
$generic_commande = new Commande ( $db );
2012-09-15 09:02:20 +02:00
2012-06-06 18:02:47 +02:00
while ( $i < $num )
2012-05-30 14:48:23 +02:00
{
$objp = $db -> fetch_object ( $resql );
2017-06-07 16:44:04 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
$generic_commande -> id = $objp -> rowid ;
$generic_commande -> ref = $objp -> ref ;
2015-09-05 10:42:54 +02:00
$generic_commande -> statut = $objp -> fk_statut ;
$generic_commande -> date_commande = $db -> jdate ( $objp -> date_commande );
$generic_commande -> date_livraison = $db -> jdate ( $objp -> date_livraison );
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
2013-04-25 01:13:13 +02:00
print '<td class="nobordernopadding nowrap">' ;
2016-08-01 16:04:49 +02:00
print $generic_commande -> getNomUrl ( 1 , 0 );
2012-05-30 14:48:23 +02:00
print '</td>' ;
2012-09-15 09:02:20 +02:00
2013-04-25 01:13:13 +02:00
print '<td width="20" class="nobordernopadding nowrap">' ;
2015-09-05 10:42:54 +02:00
if ( $generic_commande -> hasDelay ()) {
print img_picto ( $langs -> trans ( " Late " ), " warning " );
}
2012-05-30 14:48:23 +02:00
print '</td>' ;
2012-09-15 09:02:20 +02:00
2013-04-25 20:27:45 +02:00
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">' ;
2012-05-30 14:48:23 +02:00
$filename = dol_sanitizeFileName ( $objp -> ref );
$filedir = $conf -> commande -> dir_output . '/' . dol_sanitizeFileName ( $objp -> ref );
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?id=' . $objp -> rowid ;
2012-09-15 09:02:20 +02:00
print $formfile -> getDocumentsLink ( $generic_commande -> element , $filename , $filedir );
2012-05-30 14:48:23 +02:00
print '</td></tr></table>' ;
print '</td>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
print '<td>' . $objp -> ref_client . '</td>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
// Order date
2015-05-12 15:37:35 +02:00
print '<td align="center" class="nowrap">' ;
2012-07-02 19:30:37 +02:00
print dol_print_date ( $db -> jdate ( $objp -> date_commande ), 'day' );
2012-05-30 14:48:23 +02:00
print '</td>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
//Delivery date
2015-05-12 15:37:35 +02:00
print '<td align="center" class="nowrap">' ;
2012-07-02 19:30:37 +02:00
print dol_print_date ( $db -> jdate ( $objp -> date_livraison ), 'day' );
2012-05-30 14:48:23 +02:00
print '</td>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
// Statut
2018-03-16 10:51:12 +01:00
print '<td align="right" class="nowrap">' . $generic_commande -> LibStatut ( $objp -> fk_statut , $objp -> billed , 5 ) . '</td>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
// Checkbox
print '<td align="center">' ;
print '<input class="flat checkformerge" type="checkbox" name="orders_to_invoice[]" value="' . $objp -> rowid . '">' ;
print '</td>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
print '</tr>' ;
2012-09-15 09:02:20 +02:00
2012-05-30 14:48:23 +02:00
$total = $total + $objp -> price ;
$subtotal = $subtotal + $objp -> price ;
$i ++ ;
}
print '</table>' ;
2012-09-15 09:02:20 +02:00
2012-07-02 19:30:37 +02:00
/*
2012-08-07 13:12:20 +02:00
* Boutons actions
2012-05-30 14:48:23 +02:00
*/
2016-03-08 17:31:46 +01:00
print '<br><div class="center"><input type="checkbox" ' . ( empty ( $conf -> global -> INVOICE_CLOSE_ORDERS_OFF_BY_DEFAULT_FORMASSINVOICE ) ? ' checked="checked"' : '' ) . ' name="autocloseorders"> ' . $langs -> trans ( " CloseProcessedOrdersAutomatically " );
2012-07-02 19:30:37 +02:00
print '<div align="right">' ;
print '<input type="hidden" name="socid" value="' . $socid . '">' ;
print '<input type="hidden" name="action" value="create">' ;
2012-05-30 14:48:23 +02:00
print '<input type="hidden" name="origin" value="commande"><br>' ;
2012-10-03 11:53:14 +02:00
//print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>';
print '<input type="submit" class="butAction" value="' . $langs -> trans ( " GenerateBill " ) . '">' ;
2012-09-23 18:00:30 +02:00
print '</div>' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2012-05-30 14:48:23 +02:00
print '</form>' ;
$db -> free ( $resql );
}
else
{
2015-02-10 13:17:37 +01:00
dol_print_error ( $db );
2012-05-30 14:48:23 +02:00
}
2012-05-31 21:25:22 +02:00
2012-05-30 14:48:23 +02:00
}
2012-07-23 21:31:10 +02:00
llxFooter ();
$db -> close ();