本文整理匯總了PHP中Facture::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP Facture::create方法的具體用法?PHP Facture::create怎麽用?PHP Facture::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Facture
的用法示例。
在下文中一共展示了Facture::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: post
/**
* Create invoice object
*
* @param array $request_data Request datas
* @return int ID of invoice
*
* @url POST invoice/
*/
function post($request_data = NULL)
{
if (!DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}
// Check mandatory fields
$result = $this->_validate($request_data);
foreach ($request_data as $field => $value) {
$this->invoice->{$field} = $value;
}
if (!array_keys($request_data, 'date')) {
$this->invoice->date = dol_now();
}
if (!$this->invoice->create(DolibarrApiAccess::$user)) {
throw new RestException(500);
}
return $this->invoice->id;
}
示例2: createFromClone
/**
* Load an object from its id and create a new one in database
* @param fromid Id of object to clone
* @param invertdetail Reverse sign of amounts for lines
* @return int New id of clone
*/
function createFromClone($fromid, $invertdetail = 0)
{
global $conf, $user, $langs;
$error = 0;
// Load source object
$objFrom = new Facture($this->db);
$objFrom->fetch($fromid);
// Load new object
$object = new Facture($this->db);
$object->fetch($fromid);
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) {
$object->callHooks('invoicecard');
}
$this->db->begin();
$object->id = 0;
$object->statut = 0;
// Clear fields
$object->user_author = $user->id;
$object->user_valid = '';
$object->fk_facture_source = 0;
$object->date_creation = '';
$object->date_validation = '';
$object->ref_client = '';
$object->close_code = '';
$object->close_note = '';
$object->products = $object->lines;
// Tant que products encore utilise
// Loop on each line of new invoice
foreach ($object->lines as $i => $line) {
if (($object->lines[$i]->info_bits & 0x2) == 0x2) {
unset($object->lines[$i]);
unset($object->products[$i]);
// Tant que products encore utilise
}
}
// Create clone
$result = $object->create($user);
// Other options
if ($result < 0) {
$this->error = $object->error;
$error++;
}
if (!$error) {
// Hook for external modules
if (!empty($object->hooks)) {
foreach ($object->hooks as $hook) {
if (!empty($hook['modules'])) {
foreach ($hook['modules'] as $module) {
if (method_exists($module, 'createfrom')) {
$result = $module->createfrom($objFrom, $result, $object->element);
if ($result < 0) {
$error++;
}
}
}
}
}
}
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
$interface = new Interfaces($this->db);
$result = $interface->run_triggers('BILL_CLONE', $object, $user, $langs, $conf);
if ($result < 0) {
$error++;
$this->errors = $interface->errors;
}
// Fin appel triggers
}
// End
if (!$error) {
$this->db->commit();
return $object->id;
} else {
$this->db->rollback();
return -1;
}
}
示例3: testFactureRecCreate
/**
* testFactureCreate
*
* @return int
*/
public function testFactureRecCreate()
{
global $conf, $user, $langs, $db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;
$localobjectinv = new Facture($this->savdb);
$localobjectinv->initAsSpecimen();
$localobjectinv->create($user);
$localobject = new FactureRec($this->savdb);
$localobject->initAsSpecimen();
$result = $localobject->create($user, $localobjectinv->id);
$this->assertLessThan($result, 0);
print __METHOD__ . " result=" . $result . "\n";
return $result;
}
示例4: createInvoice
/**
* Create an invoice
*
* @param array $authentication Array of authentication information
* @param Facture $invoice Invoice
* @return array Array result
*/
function createInvoice($authentication, $invoice)
{
global $db, $conf, $langs;
$now = dol_now();
dol_syslog("Function: createInvoiceForThirdParty login=" . $authentication['login']);
if ($authentication['entity']) {
$conf->entity = $authentication['entity'];
}
// Init and check authentication
$objectresp = array();
$errorcode = '';
$errorlabel = '';
$error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
if (!$error) {
$newobject = new Facture($db);
$newobject->socid = $invoice['thirdparty_id'];
$newobject->type = $invoice['type'];
$newobject->ref_ext = $invoice['ref_ext'];
$newobject->date = dol_stringtotime($invoice['date'], 'dayrfc');
$newobject->note_private = $invoice['note_private'];
$newobject->note_public = $invoice['note_public'];
$newobject->statut = 0;
// We start with status draft
$newobject->fk_project = $invoice['project_id'];
$newobject->date_creation = $now;
// Trick because nusoap does not store data with same structure if there is one or several lines
$arrayoflines = array();
if (isset($invoice['lines']['line'][0])) {
$arrayoflines = $invoice['lines']['line'];
} else {
$arrayoflines = $invoice['lines'];
}
foreach ($arrayoflines as $key => $line) {
// $key can be 'line' or '0','1',...
$newline = new FactureLigne($db);
$newline->product_type = $line['type'];
$newline->desc = $line['desc'];
$newline->fk_product = $line['fk_product'];
$newline->tva_tx = $line['vat_rate'];
$newline->qty = $line['qty'];
$newline->subprice = $line['unitprice'];
$newline->total_ht = $line['total_net'];
$newline->total_tva = $line['total_vat'];
$newline->total_ttc = $line['total'];
$newline->date_start = dol_stringtotime($line['date_start']);
$newline->date_end = dol_stringtotime($line['date_end']);
$newline->fk_product = $line['product_id'];
$newobject->lines[] = $newline;
}
//var_dump($newobject->date_lim_reglement); exit;
//var_dump($invoice['lines'][0]['type']);
$db->begin();
$result = $newobject->create($fuser, 0, dol_stringtotime($invoice['date_due'], 'dayrfc'));
if ($result < 0) {
$error++;
}
if ($invoice['status'] == 1) {
$result = $newobject->validate($fuser);
if ($result < 0) {
$error++;
}
}
if (!$error) {
$db->commit();
$objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref);
} else {
$db->rollback();
$error++;
$errorcode = 'KO';
$errorlabel = $newobject->error;
}
}
if ($error) {
$objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
return $objectresp;
}
示例5: rand
$i++;
$row = $db->fetch_row($resql);
$prodids[$i] = $row[0];
}
}
$i = 0;
$result = 0;
while ($i < GEN_NUMBER_FACTURE && $result >= 0) {
$i++;
$socid = rand(1, $num_socs);
print "Invoice " . $i . " for socid " . $socid;
$facture = new Facture($db, $socids[$socid]);
$facture->date = time();
$facture->cond_reglement_id = 3;
$facture->mode_reglement_id = 3;
$result = $facture->create($user);
if ($result >= 0) {
$result = $facture->validate($user);
if ($result) {
$nbp = rand(2, 5);
$xnbp = 0;
while ($xnbp < $nbp) {
$prodid = rand(1, $num_prods);
$product = new Product($db);
$result = $product->fetch($prodids[$prodid]);
$result = $facture->addline($facture->id, $product->description, $product->price, rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
$xnbp++;
}
print " OK with ref " . $facture->ref . "\n";
} else {
dol_print_error($db, $facture->error);
示例6: Facture
(at your option) any later version.
Webfinance 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 Webfinance; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
include "../inc/main.php";
if (!is_numeric($_GET['id_facture'])) {
$Facture = new Facture();
$invoice = array('client_id' => $_GET['id_client'], 'rows' => array());
$id_facture = $Facture->create($invoice);
header("Location: edit_facture.php?id_facture=" . $id_facture);
die;
}
$Facture = new Facture();
$facture = $Facture->getInfos($_GET['id_facture']);
list($currency, $exchange) = getCurrency($facture->id_compte);
$title = $facture->nom_client;
$roles = 'manager,employee,accounting';
include "../top.php";
include "nav.php";
?>
<script type="text/javascript" language="javascript"
src="/js/ask_confirmation.js"></script>
示例7: isset
$invoice->lines[] = $invoiceline;
}
$invoice->socid = $conf_fksoc;
$invoice->date_creation = $now;
$invoice->date = $now;
$invoice->date_lim_reglement = 0;
$invoice->total_ht = $obj_facturation->prixTotalHt();
$invoice->total_tva = $obj_facturation->montantTva();
$invoice->total_ttc = $obj_facturation->prixTotalTtc();
$invoice->note = $note;
$invoice->cond_reglement_id = $cond_reglement_id;
$invoice->mode_reglement_id = $mode_reglement_id;
//print "c=".$invoice->cond_reglement_id." m=".$invoice->mode_reglement_id; exit;
// Si paiement differe ...
if ($obj_facturation->getSetPaymentMode() == 'DIF') {
$resultcreate = $invoice->create($user, 0, dol_stringtotime($obj_facturation->paiementLe()));
if ($resultcreate > 0) {
$resultvalid = $invoice->validate($user, $obj_facturation->numInvoice());
} else {
$error++;
}
$id = $invoice->id;
} else {
$resultcreate = $invoice->create($user, 0, 0);
if ($resultcreate > 0) {
$resultvalid = $invoice->validate($user, $obj_facturation->numInvoice(), isset($_SESSION["CASHDESK_ID_WAREHOUSE"]) ? $_SESSION["CASHDESK_ID_WAREHOUSE"] : 0);
$id = $invoice->id;
// Add the payment
$payment = new Paiement($db);
$payment->datepaye = $now;
$payment->bank_account = $conf_fkaccount;
示例8: CreateFacture
/**
*
* Create facture into Database
*
* @param array $aryTicket Ticket object
*/
private function CreateFacture($aryTicket)
{
global $db, $user, $conf;
$function = "CreateFacture";
$idFacture = -1;
$data = $aryTicket['data'];
$lines = $data['lines'];
$idTicket = $data["id"];
if ($data['idsource'] > 0) {
$prods_returned = self::testSourceFac($aryTicket);
if (sizeof($prods_returned) > 0) {
return -6;
}
$vater = new Facture($db);
$vater->fetch($data['idsource']);
$data['payment_type'] = $vater->mode_reglement_id;
}
$cash = new Cash($db);
$terminal = $data['cashId'];
$cash->fetch($terminal);
if (!$data['customerId']) {
$socid = $cash->fk_soc;
$data['customerId'] = $socid;
} else {
$socid = $data['customerId'];
}
if (!$data['employeeId']) {
$employee = $_SESSION['uid'];
} else {
$employee = $data['employeeId'];
}
if ($data['mode'] == 1) {
$object = new Facturesim($db);
} else {
$object = new Facture($db);
}
$object->type = $data['type'] == 0 ? 0 : 2;
$object->socid = $socid;
$object->statut = $data['state'];
$object->fk_cash = $terminal;
$object->remise_percent = $data['discount_percent'];
$object->remise_absolue = $data['discount_qty'];
if ($data['customerpay1'] > 0) {
$object->mode_reglement_id = $cash->fk_modepaycash;
} else {
if ($data['customerpay2'] > 0) {
$object->mode_reglement_id = $cash->fk_modepaybank;
} else {
$object->mode_reglement_id = $cash->fk_modepaybank_extra;
}
}
$object->fk_place = $data['id_place'];
$object->note_private = $data['note'];
$object->customer_pay = $data['customerpay'];
if ($object->customer_pay > 0) {
$object->diff_payment = $data['difpayment'];
} else {
$object->diff_payment = $data['total'];
}
$object->fk_facture_source = $data['idsource'];
$employ = new User($db);
$employ->fetch($employee);
$employ->getrights();
$now = dol_now();
$object->date = $now;
$db->begin;
$idFacture = $object->create($employ);
if ($object->statut == 1 || $object->type == 2) {
$res = $object->validate($employ);
if ($res < 0) {
$soc = new Societe($db);
$soc->fetch($socid);
$num = $object->getNextNumRef($soc);
// Validate
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture';
$sql .= " SET facnumber='" . $num . "', fk_statut = 1, fk_user_valid = " . $employ->id . ", date_valid = '" . $db->idate($now) . "'";
if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
$sql .= ', datef=' . $db->idate($now);
$sql .= ', date_lim_reglement=' . $db->idate($now);
}
$sql .= ' WHERE rowid = ' . $object->id;
dol_syslog(get_class($this) . "::validate sql=" . $sql);
$resql = $db->query($sql);
$object->ref = $num;
}
}
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'pos_facture (fk_cash, fk_place,fk_facture,customer_pay) VALUES (' . $object->fk_cash . ',' . ($object->fk_place ? $object->fk_place : 'null') . ',' . $idFacture . ',' . $object->customer_pay . ')';
dol_syslog("pos_facture::update sql=" . $sql);
$resql = $db->query($sql);
if (!$resql) {
$this->db->rollback();
return -1;
}
$data['ref'] = $object->ref;
//.........這裏部分代碼省略.........
示例9: createFromCurrent
/**
* Create a new invoice in database from current invoice
*
* @param User $user Object user that ask creation
* @param int $invertdetail Reverse sign of amounts for lines
* @return int <0 if KO, >0 if OK
*/
function createFromCurrent($user, $invertdetail = 0)
{
global $conf;
// Charge facture source
$facture = new Facture($this->db);
$facture->fk_facture_source = $this->fk_facture_source;
$facture->type = $this->type;
$facture->socid = $this->socid;
$facture->date = $this->date;
$facture->note_public = $this->note_public;
$facture->note_private = $this->note_private;
$facture->ref_client = $this->ref_client;
$facture->modelpdf = $this->modelpdf;
$facture->fk_project = $this->fk_project;
$facture->cond_reglement_id = $this->cond_reglement_id;
$facture->mode_reglement_id = $this->mode_reglement_id;
$facture->remise_absolue = $this->remise_absolue;
$facture->remise_percent = $this->remise_percent;
$facture->origin = $this->origin;
$facture->origin_id = $this->origin_id;
$facture->lines = $this->lines;
// Tableau des lignes de factures
$facture->products = $this->lines;
// Tant que products encore utilise
$facture->situation_counter = $this->situation_counter;
$facture->situation_cycle_ref = $this->situation_cycle_ref;
$facture->situation_final = $this->situation_final;
// Loop on each line of new invoice
foreach ($facture->lines as $i => $line) {
$facture->lines[$i]->fk_prev_id = $this->lines[$i]->rowid;
if ($invertdetail) {
$facture->lines[$i]->subprice = -$facture->lines[$i]->subprice;
$facture->lines[$i]->total_ht = -$facture->lines[$i]->total_ht;
$facture->lines[$i]->total_tva = -$facture->lines[$i]->total_tva;
$facture->lines[$i]->total_localtax1 = -$facture->lines[$i]->total_localtax1;
$facture->lines[$i]->total_localtax2 = -$facture->lines[$i]->total_localtax2;
$facture->lines[$i]->total_ttc = -$facture->lines[$i]->total_ttc;
}
}
dol_syslog(get_class($this) . "::createFromCurrent invertdetail=" . $invertdetail . " socid=" . $this->socid . " nboflines=" . count($facture->lines));
$facid = $facture->create($user);
if ($facid <= 0) {
$this->error = $facture->error;
$this->errors = $facture->errors;
} elseif ($this->type == self::TYPE_SITUATION && !empty($conf->global->INVOICE_USE_SITUATION)) {
$this->fetchObjectLinked('', '', $object->id, 'facture');
foreach ($this->linkedObjectsIds as $typeObject => $Tfk_object) {
foreach ($Tfk_object as $fk_object) {
$facture->add_object_linked($typeObject, $fk_object);
}
}
$facture->add_object_linked('facture', $this->fk_facture_source);
}
return $facid;
}
示例10: testFactureRoundingCreate2
/**
* testFactureRoundingCreate2
*
* @return int
*
* @depends testFactureRoundingCreate1
* Test according to page http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage
*/
public function testFactureRoundingCreate2()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen();
$localobject->lines=array();
unset($localobject->total_ht);
unset($localobject->total_ttc);
unset($localobject->total_vat);
$result=$localobject->create($user);
// Add two lines
for ($i=0; $i<2; $i++)
{
$localobject->addline($result, 'Description '.$i, 1.24, 1, 10);
}
$newlocalobject=new Facture($this->savdb);
$newlocalobject->fetch($result);
//var_dump($newlocalobject);
$this->assertEquals($newlocalobject->total_ht, 2.48);
//$this->assertEquals($newlocalobject->total_tva, 0.25);
//$this->assertEquals($newlocalobject->total_ttc, 2.73);
return $result;
}
示例11: createAndSendInvoice
function createAndSendInvoice($id_client, $prix_ht, $quantity, $description, $delivery_method)
{
# No invoice if amount is zero
if ($prix_ht * $quantity <= 0) {
return true;
}
$Facture = new Facture();
$invoice = array('client_id' => $id_client, 'rows' => array());
$id_facture = $Facture->create($invoice);
// Get invoice payment
$res = mysql_query("SELECT payment_method\n FROM webfinance_invoices i\n WHERE id_client = {$id_client}\n AND type_doc = 'facture'\n AND is_envoye = 1\n AND payment_method IS NOT NULL\n AND is_abandoned = 0\n ORDER BY id_facture DESC\n LIMIT 1") or die(mysql_error());
# Default values
$payment_method = 'unknown';
if (mysql_num_rows($res) > 0) {
$type_payment_res = mysql_fetch_array($res);
$payment_method = $type_payment_res['payment_method'];
}
// Get id_compte
$result = mysql_query('SELECT id_pref,value ' . 'FROM webfinance_pref ' . "WHERE type_pref='rib' " . 'LIMIT 1') or die(mysql_error());
$cpt = mysql_fetch_object($result);
$id_compte = $cpt->id_pref;
// Get id_type_presta
$result = mysql_query("SELECT id_type_presta\n FROM webfinance_type_presta\n WHERE nom = 'Support mensuel'\n LIMIT 1") or die(mysql_error());
list($id_type_presta) = mysql_fetch_row($result);
// Input facture parameters
mysql_query("UPDATE webfinance_invoices SET\n\t\t is_paye = 0,\n\t\t is_envoye = 0,\n\t\t ref_contrat = 'Support professionnel',\n\t\t payment_method = '{$payment_method}',\n\t\t id_compte = {$id_compte},\n\t\t id_type_presta = {$id_type_presta}\n\t\t WHERE id_facture = {$id_facture}") or die(mysql_error());
// Add service rows to invoice
$q = sprintf("INSERT INTO webfinance_invoice_rows (id_facture,description,prix_ht,qtt,ordre) " . "SELECT %d, '%s', %s, %s, if(max(ordre) is null, 1, max(ordre + 1)) " . "FROM webfinance_invoice_rows " . "WHERE id_facture=%d", $id_facture, mysql_real_escape_string($description), $prix_ht, $quantity, $id_facture);
$result = mysql_query($q) or die(mysql_error());
mysql_query("UPDATE webfinance_invoices SET date_generated=NULL WHERE id_facture=" . $id_facture) or die(mysql_error());
if ($payment_method == 'direct_debit') {
// Plan the invoice to be debited
mysql_query("INSERT INTO direct_debit_row " . "SET invoice_id = {$id_facture}, " . " state='todo'") or die(mysql_error());
// Flag invoice as paid
$Facture->setPaid($id_facture);
}
// Manage invoice delivery and send by email to client
switch ($delivery_method) {
case 'email':
$Facture->sendByEmail($id_facture) or die("Unable to send email for invoice ID {$id_facture}");
break;
case 'postal':
$send_mail_print_invoice = true;
$attachments[] = $Facture->generatePDF($id_facture, true);
$Facture->setSent($id_facture);
break;
}
return true;
}
示例12: createInvoice
/**
* Get list of invoices for third party
*/
function createInvoice($authentication,$invoice)
{
global $db,$conf,$langs;
$now=dol_now();
dol_syslog("Function: createInvoiceForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
// Init and check authentication
$objectresp=array();
$errorcode='';$errorlabel='';
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
// Check parameters
if (! $error)
{
$newinvoice=new Facture($db);
$newinvoice->socid=$invoice['thirdparty_id'];
$newinvoice->type=$invoice['type'];
$newinvoice->ref_ext=$invoice['ref_ext'];
$newinvoice->date=$invoice['date'];
$newinvoice->date_lim_reglement=$invoice['date_due'];
$newinvoice->note=$invoice['note'];
$newinvoice->note_public=$invoice['note_public'];
$newinvoice->statut=$invoice['status'];
$newinvoice->fk_project=$invoice['project_id'];
$newinvoice->date_creation=$now;
foreach($invoice['lines'] as $line)
{
$newline=new FactureLigne($db);
$newline->type=$line['type'];
$newline->desc=$line['desc'];
$newline->fk_product=$line['fk_product'];
$newline->total_ht=$line['total_net'];
$newline->total_vat=$line['total_vat'];
$newline->total_ttc=$line['total'];
$newline->vat=$line['vat_rate'];
$newline->qty=$line['qty'];
$newline->fk_product=$line['product_id'];
}
//var_dump($invoice['ref_ext']);
//var_dump($invoice['lines'][0]['type']);
$db->begin();
$result=$newinvoice->create($user,0,0);
if ($result < 0)
{
$error++;
}
if ($newinvoice->statut == 1) // We want invoice validated
{
$newinvoice->validate($user);
}
$result=$newinvoice->create($user,0,0);
if ($result < 0)
{
$error++;
}
if (! $error)
{
$db->commit();
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newinvoice->id,'ref'=>$newinvoice->ref);
}
else
{
$db->rollback();
$error++;
$errorcode='KO';
$errorlabel=$newinvoice->error;
}
}
if ($error)
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
return $objectresp;
}
示例13: _createAvoir
function _createAvoir(&$PDOdb, &$db, &$user, &$conf, &$langs)
{
dol_include_once('/compta/facture/class/facture.class.php');
dol_include_once('/core/class/discount.class.php');
$sql = _getSql2();
$PDOdb->Execute($sql);
$TFacnumberFetchError = array();
$TFacnumberCreateError = array();
$TDiscountCreateError = array();
$nbValidate = 0;
while ($row = $PDOdb->Get_line()) {
$fk_soc = $row->fk_soc;
$facnumber = $row->facnumber;
$factureImpayee = new Facture($db);
if ($factureImpayee->fetch(null, $facnumber) <= 0) {
$TFacnumberFetchError[] = $facnumber;
continue;
}
$dateinvoice = dol_mktime(12, 0, 0, date('m'), date('d'), date('Y'));
$facture = new Facture($db);
$facture->socid = $fk_soc;
$facture->fk_facture_source = $factureImpayee->id;
$facture->type = Facture::TYPE_CREDIT_NOTE;
$facture->date = $dateinvoice;
if ($facture->create($user) <= 0) {
$TFacnumberCreateError[] = $facnumber;
continue;
}
foreach ($factureImpayee->lines as $line) {
$line->fk_facture = $facture->id;
$line->subprice = -$line->subprice;
// invert price for object
$line->pa_ht = -$line->pa_ht;
$line->total_ht = -$line->total_ht;
$line->total_tva = -$line->total_tva;
$line->total_ttc = -$line->total_ttc;
$line->total_localtax1 = -$line->total_localtax1;
$line->total_localtax2 = -$line->total_localtax2;
$line->insert();
$facture->lines[] = $line;
// insert new line in current object
}
$facture->update_price(1);
$facture->validate($user);
$discountcheck = new DiscountAbsolute($db);
$result = $discountcheck->fetch(0, $facture->id);
if (!empty($discountcheck->id)) {
//can't convert
$facture->delete();
continue;
}
$i = 0;
$amount_ht = $amount_tva = $amount_ttc = array();
foreach ($facture->lines as $line) {
if ($line->total_ht != 0) {
// no need to create discount if amount is null
$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);
$discount->description = '(CREDIT_NOTE)';
$discount->tva_tx = abs($facture->total_ttc);
$discount->fk_soc = $facture->socid;
$discount->fk_facture_source = $facture->id;
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) {
$TDiscountCreateError[] = $facnumber;
$error++;
break;
}
$result = $facture->set_paid($user);
$result = $discount->link_to_invoice(0, $factureImpayee->id);
$r = $factureImpayee->set_paid($user);
}
/******/
$nbValidate++;
}
if ($nbValidate) {
setEventMessages($langs->trans('sendinvoicetoadherentAvoirValidate', $nbValidate), null);
}
if (count($TFacnumberFetchError) > 0) {
setEventMessages($langs->trans('sendinvoicetoadherentErrorFetchFacture', count($TFacnumberFetchError)), null, 'errors');
}
if (count($TFacnumberCreateError) > 0) {
setEventMessages($langs->trans('sendinvoicetoadherentErrorCreateAvoir', count($TFacnumberCreateError)), null, 'errors');
}
$_SESSION['SENDTOINVOICETOADHERENT_TFETCHERROR'] = $TFacnumberFetchError;
$_SESSION['SENDTOINVOICETOADHERENT_TCREATEERROR'] = $TFacnumberCreateError;
header('Location: ' . dol_buildpath('/sendinvoicetoadherent/sendinvoicetoadherent.php?action=listAvoir', 2));
exit;
}
開發者ID:ATM-Consulting,項目名稱:dolibarr_module_sendinvoicetoadherent,代碼行數:100,代碼來源:sendinvoicetoadherent.php
示例14: testFactureAddLine3
/**
* testFactureAddLine3
*
* @return void
*
* @depends testFactureAddLine2
* The depends says test is run only if previous is ok
*/
public function testFactureAddLine3()
{
global $conf, $user, $langs, $db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;
// With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0
$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0;
$localobject3 = new Facture($this->savdb);
$localobject3->initAsSpecimen('nolines');
$facid = $localobject3->create($user);
$localobject3->addline('Line 1', 6.36, 3, 21);
$localobject3->addline('Line 2', 6.36, 3, 21);
$localobject3->addline('Line 3', 6.36, 3, 21);
$localobject3->addline('Line 4', 6.36, 3, 21);
$localobject3->addline('Line 5', 6.36, 3, 21);
print __METHOD__ . " id=" . $facid . " total_ttc=" . $localobject3->total_ttc . "\n";
$this->assertEquals(95.40000000000001, $localobject3->total_ht);
$this->assertEquals(20.05, $localobject3->total_tva);
$this->assertEquals(115.45, $localobject3->total_ttc);
// With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1
$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1;
$localobject3 = new Facture($this->savdb);
$localobject3->initAsSpecimen('nolines');
$facid = $localobject3->create($user);
$localobject3->addline('Line 1', 6.36, 3, 21);
$localobject3->addline('Line 2', 6.36, 3, 21);
$localobject3->addline('Line 3', 6.36, 3, 21);
$localobject3->addline('Line 4', 6.36, 3, 21);
$localobject3->addline('Line 5', 6.36, 3, 21);
print __METHOD__ . " id=" . $facid . " total_ttc=" . $localobject3->total_ttc . "\n";
$this->assertEquals(95.40000000000001, $localobject3->total_ht);
$this->assertEquals(20.03, $localobject3->total_tva);
$this->assertEquals(115.43, $localobject3->total_ttc);
}
示例15: trim
$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'];
if ($_POST['origin'] && $_POST['originid']) {
$object->origin = $_POST['origin'];
$object->origin_id = $orders_id[$ii];
$object->linked_objects = $orders_id;
$id = $object->create($user);
$object->fetch_thirdparty();
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 . "'";