noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Acc_Ledger_Purchase Class Reference

: input, confirm and save new operations in edger of purchase the $_POST data is an array with these keys More...

+ Inheritance diagram for Acc_Ledger_Purchase:
+ Collaboration diagram for Acc_Ledger_Purchase:

Public Member Functions

 __construct ($p_cn, $p_init)
 construct
 
 confirm ($p_array, $p_summary=false)
 show the summary of the operation and propose to save it
 
 input ($p_array=null, $p_readonly=0)
 display the form for entering data for invoice
 
 insert ($p_array=null)
 insert into the database, it calls first the verify function change the value of this->jr_id and this->jr_internal. It generates the document and save the middle of payment, if 'gen_invoice is set and e_mp
 
 verify_operation ($p_array)
 verify that the data are correct before inserting or confirming
 
- Public Member Functions inherited from Acc_Ledger
 add_card ($p_filter, $p_id_update)
 Return a button to create new card, depending of the ledger.
 
 button_copy_operation ()
 Show a button to create an operation identical to the recorded one.
 
 button_new_operation ()
 Create a button to encode a new operation into the same ledger.
 
 check_currency ($p_qcode_payment, $p_currency_id)
 When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo reliable , all the bank operation must be in the same currency Operation = Currency 1 and Bank = Currency 2 then it must failed , except if currency 2 (of the bank is the default currency.
 
 check_currency_setting ($p_currency_code)
 Check that the currency code does exist and the setting of the folder is correct.
 
 check_payment ($e_mp, $e_mp_qcode)
 check if the payment method is valid
 
 check_periode ()
 Check if a Dossier is using the check on the periode, if true than the user has to enter the date and the periode, it is a security check.
 
 check_strict ()
 Check if a Dossier is using the strict mode or not.
 
 compute_internal_code ($p_grpt)
 compute the internal code of the saved operation and set the $this->jr_internal to the computed value
 
 convert_from_follow ($p_ag_id, $copy_description=0)
 convert operations from FOLLOWUP into a SALE , FEENOTE or PURCHASE operation into a suitable array
 
 create_document ($internal, $p_array)
 alias for Acc_Document->create_document
 
 CurrencyInput ($p_currency_code, $p_currency_rate, $p_eur_amount)
 Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amount.
 
 delete ()
 let you delete a operation
 
 delete_ledger ()
 delete a ledger IF it doesn't contain anything
 
 display_additional_tax ($p_additional_tax, $p_amount)
 in confirm screen , display the compute value for additional tax @parameter $p_additional_tax acc_other_tax.ac_id
 
 display_ledger ()
 display detail of a ledger
 
 display_negative_warning ($p_amount)
 If the amount is positive and the ledger expects a negative amount, il will return the saved warning.
 
 display_warning ($pa_msg, $p_warning)
 Display warning contained in an array.
 
 existing_vat ()
 return the used VAT code with a rate > 0
 
 get_all_fiche_def ()
 retrieve all the card for this type of ledger, make them into a string separated by comma
 
 get_class_def ()
 retrieve the jrn_def_class_deb and return it
 
 get_currency ()
 returns the code iso of the default currency for this ledger
 
 get_customer_late ()
 get info from customer not yet paid
 
 get_customer_now ()
 get info from customer to pay today
 
 get_default_card ($p_ledger_type, $p_side)
 Return an array of default card for the ledger type given.
 
 get_fiche_def ()
 retrieve the jrn_def_fiche and return them into a array index deb, cred
 
 get_first ($p_type, $p_access=3)
 get the first ledger
 
 get_id ($p_internal)
 retrieve the jr_id thanks the internal code, do not change anything to the current object
 
 get_is_loaded ()
 
 get_last ($p_limit)
 return the last p_limit operation into an array
 
 get_last_date ()
 get the date of the last operation
 
 get_last_pj ()
 returns the sequence number of the receipt for the current ledger or create the sequence if it doesn't exist
 
 get_ledger_id ()
 Set the jrn_def.jrn_def_id.
 
 get_min_row ()
 
 get_name ()
 Return the name of a ledger.
 
 get_operation ($p_from, $p_to)
 retrieve operation from jrn
 
 get_operation_date ($p_date, $p_ledger_type, $sql_op)
 Get operation from the ledger type before, after or with the given date .
 
 get_other_amount ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 get_propertie ()
 Get the properties of a journal.
 
 get_rowSimple ($p_from, $p_to, $pa_ledger=[], $trunc=0, $p_limit=-1, $p_offset=-1)
 Get simplified row from ledger Call Acc_Ledger_History_Generic:get_rowSimple.
 
 get_solde ($p_from, $p_to)
 get the saldo of a ledger for a specific period
 
 get_supplier_late ()
 get info from supplier not yet paid
 
 get_supplier_now ()
 get info from supplier to pay today
 
 get_tiers ($p_jrn_type, $jr_id)
 Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
 
 get_tiers_id ($p_jrn_type, $jr_id)
 Return the f_id of the tiers , called by get_tiers.
 
 get_type ()
 Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
 
 guess_pj ()
 guess what the next pj should be
 
 has_other_tax ()
 returns true if the ledger has an additional tax
 
 has_quantity ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 inc_seq_pj ()
 increment the sequence for the pj
 
 input_additional_tax ()
 form : display additional tax available for this ledger and value, set 2 values : checkbox if tax applies and value
 
 input_extra_info ()
 
 input_new ()
 display FORM to enter parameters to create a new ledger.
 
 input_paid ($p_selected, $p_amount=0, $p_date="", $p_comm="")
 Create the section payment.
 
 is_closed ($p_periode)
 check if the current ledger is closed
 
 is_enable ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 listing ()
 listing of all ledgers
 
 previous_amount ($p_to)
 retrieve amount of previous periode
 
 previous_other_tax ($p_to)
 retrieve the previous amount
 
 reverse ($p_date, $p_label)
 reverse the operation by creating the opposite one, the result is to avoid it it must be done in
 
 save ($p_array=null)
 save the operation into the jrnx,jrn, , CA and pre_def
 
 save_followup ($s_related_action)
 attach action-followups to an operation,
 
 save_new ($array)
 Insert a new ledger , member variable like jrn_def_id will changed.
 
 search_group ($p_what, $p_value)
 retreive the jr_grpt_id from a ledger
 
 select_default_currency ()
 create a select button to set the default currency for a ledger used only for empty financial ledger
 
 select_depot ($p_readonly, $p_repo)
 Let you select the repository before confirming a sale or a purchase.
 
 select_ledger ($p_type="ALL", $p_access=3, $enable=TRUE)
 Show a select list of the ledgers you can access in writing, reading or simply accessing.
 
 set_currency_id ()
 retrieve currency_id from database
 
 set_is_loaded ($is_loaded)
 
 set_ledger_id ($p_id)
 Set the jrn_def.jrn_def_id.
 
 set_quantity ($p_value)
 set quantity for the ledger to 1 or 0,
 
 update ($array=null)
 update a ledger
 
 update_internal_code ($p_internal)
 
 update_paid ($p_array)
 Update the paiment in the list of operation.
 
 upload_supplemental_document ($jr_id)
 upload the supplementary documents and attach them to the JRN.JR_ID start a new transaction if the connection to the database is not already in a transaction
 
 use_quant_table ($p_grpt_id, $p_jrn_type)
 Check if the operation is used in the table quant*.
 
 vat_operation ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 verify_ledger ($array)
 Verify before update.
 

Private Member Functions

 compute_no_deductible (Acc_Compute $p_nd_amount, Fiche $p_fiche)
 Compute the ND amount thanks the attribute of the concerned card.
 
 insert_no_deductible (Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both, &$p_tot_debit, Acc_Operation $p_acc_operation, $p_group, $idx)
 Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT.
 

Private Attributes

 $payment_operation
 

Additional Inherited Members

- Static Public Member Functions inherited from Acc_Ledger
static array_cat ()
 create an array of the existing cat, to be used in a checkbox form
 
static next_number ($p_cn, $p_type)
 retrieve the next number for this type of ledger
 
static test_me ($pCase='')
 this function is intended to test this class
 
- Data Fields inherited from Acc_Ledger
 $currency_id
 
 $db
 
 $doc
 
 $id
 
 $jr_grpt_id
 
 $jr_id
 
 $jr_internal
 
 $jrn_deb_max_line
 
 $jrn_def_description
 
 $jrn_def_ech_lib
 
 $jrn_def_id
 
 $jrn_def_max_line_deb
 
 $jrn_def_name
 
 $jrn_def_negative_amount
 
 $jrn_def_negative_warning
 
 $jrn_def_pj_pref
 
 $jrn_def_quantity
 
 $jrn_def_type
 
 $jrn_enable
 
 $ledger_name
 
 $ledger_type
 
 $nb
 
 $pj
 !
 
 $row
 
 $with_concerned
 
- Protected Member Functions inherited from Acc_Ledger
 find_label ($p_value)
 Retrieve the label of an accounting.
 
 input_supplemental_document ()
 display INPUT type to ask the supplementary documents
 
 verify_autonumber ($p_array)
 compare given receipt number and suggested one, if different , it means that the user enters a receipt number if e_pj or e_pj_suggest is not set or empty , or if both are equals then will return true, it returns only if they exist and are different
 
 warn_manual_receipt ($p_array)
 warn if the suggested receipt and receipt are different , it means that the user tried to number himself
 
- Protected Attributes inherited from Acc_Ledger
 $is_loaded
 

Detailed Description

: input, confirm and save new operations in edger of purchase the $_POST data is an array with these keys

Array
(
// =====================
// ANALYTIC PART
// =====================
[pa_id] => Array
(
[0] => 1
)
[op] => Array
(
[0] => 0
)
[amount_t0] => 10
[hplan] => Array
(
[0] => Array
(
[0] => -1
)
)
[val] => Array
(
[0] => Array
(
[0] => 10
)
)
// =====================
// SALES DATA
// =====================
[e_client] => QuickCode supplier
[nb_item] => number of items (lines of invoice)
[p_jrn] => JRN_DEF.JRN_DEF_ID id of the ledger
[jrn_note_input] => Note JRN_NOTE.N_TEXT
[mt] => 1759130008.8134
[p_currency_rate] => Currency Rate
[p_currency_code] => Currency Code
[e_comm] => Description of invoice
[e_date] => date invoice
[e_ech] => limit date
[e_pj] => Receipt number
[e_pj_suggest] => suggested receipt number
[e_mp] => payment means (
[jrn_type] => Type of ledger (always ACH)
//---------------------------------------------
// For each invoice line
//---------------------------------------------
[e_march0] => QuickCode of the item
[e_march0_label] => label
[e_march0_price] => unit price
[e_march0_tva_id] => VAT ID
[e_march0_tva_amount] => amount of VAT
[e_quant0] => quantity of item
//========================
// MISC
//========================
[repo] => 1 (repository)
[gen_invoice] => on (it is asked to generate an invoice
[gen_doc] => Document template id
[bon_comm] => JRN_INFO.
[other_info] = JRN_INFO.>
[opd_name] => Name of operation template
[od_description] => Description of operation template
[reverse_date] => if reverse is asked
[ext_label] => Label for revese operation
[jr_optype] => Type of operation NOR:Normal,, EXT; reverse, ..
)
$anc pa_id
$ret label
$anc_grandlivre to
reverse($p_date, $p_label)
reverse the operation by creating the opposite one, the result is to avoid it it must be done in
Class Document corresponds to the table DOCUMENT.

Definition at line 113 of file acc_ledger_purchase.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Ledger_Purchase::__construct ( $p_cn,
$p_id )

construct

Parameters
$p_cndatabase connexion
$p_id(int) ledger idf jrn.jrn_def_id

Reimplemented from Acc_Ledger.

Definition at line 117 of file acc_ledger_purchase.class.php.

118 {
119 $this->ledger_type='ACH';
120 parent::__construct($p_cn,$p_init);
121 $this->payment_operation=-1;
122 }

Member Function Documentation

◆ compute_no_deductible()

Acc_Ledger_Purchase::compute_no_deductible ( Acc_Compute $p_nd_amount,
Fiche $p_fiche )
private

Compute the ND amount thanks the attribute of the concerned card.

The object $p_nd_amount will changed

Parameters
Acc_Compute$p_nd_amountobject with ND amount
Fiche$p_ficheConcerned Card (purchase items)
type$p_tva_bot0 TVA on one side, 1 TVA on both side

Definition at line 381 of file acc_ledger_purchase.class.php.

382 {
384 {
385 $p_nd_amount->amount_nd_rate = $p_fiche->get_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
386 $p_nd_amount->compute_nd();
387 }
389 {
390 $p_nd_amount->nd_vat_rate = $p_fiche->get_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE);
391 $p_nd_amount->compute_nd_vat();
392 }
394 {
395 $p_nd_amount->nd_ded_vat_rate = $p_fiche->get_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
396 $p_nd_amount->compute_ndded_vat();
397 }
398
399 if (!$p_fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
400 {
401 $p_nd_amount->amount_perso_rate = $p_fiche->get_attribute(ATTR_DEF_DEP_PRIV);
402 $p_nd_amount->compute_perso();
403 }
404
405 }
compute_nd()
Compute the no deductible part of the amount, it reduce also the vat.
empty_attribute($p_attr)
check if an attribute is empty
get_attribute($p_ad_id, $p_return=1)
return the string of the given attribute (attr_def.ad_id)
const ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP
Definition constant.php:243
const ATTR_DEF_DEP_PRIV
Definition constant.php:240
const ATTR_DEF_TVA_NON_DEDUCTIBLE
Definition constant.php:242
const ATTR_DEF_DEPENSE_NON_DEDUCTIBLE
Definition constant.php:241

References ATTR_DEF_DEP_PRIV, ATTR_DEF_DEPENSE_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP, Acc_Compute\compute_nd(), Acc_Compute\compute_nd_vat(), Acc_Compute\compute_ndded_vat(), Acc_Compute\compute_perso(), Fiche\empty_attribute(), and Fiche\get_attribute().

Referenced by insert().

+ Here is the call graph for this function:

◆ confirm()

Acc_Ledger_Purchase::confirm ( $p_array,
$p_summary = false )

show the summary of the operation and propose to save it

Parameters
arraycontains normally $_POST. It proposes also to save the Analytic accountancy
$p_summarytrue to confirm false, show only the result in RO
Returns
string

Payment method

the function extra info allows to

  • add a attachment
  • generate an invoice
  • insert extra info
    Returns
    html string
    update the payment
    Todo
    to remove, obsolete
    Todo
    Deprecated

Retrieve data from the view v_detail_purchase

Note
$g_user connected user
Parameters
$p_fromjrn.jr_tech_per from
$p_endjrn.jr_tech_per to
Returns
handle to database result

compute an array with the heading cells for the details, used for the export in CSV

Returns
array

Reimplemented from Acc_Ledger.

Definition at line 1655 of file acc_ledger_purchase.class.php.

References $acompte, $amount, $anc, $date_limit, $default_currency, $e_date, $fiche, $g_parameter, $g_user, $i, Acc_Ledger\$jr_id, $jrn_type, $op, $other_tax_amount, $p_array, $p_jrn, Acc_Ledger\$pj, $r, $span, $str_code, $tot, $tot_amount, $value, $x, _, ATTR_DEF_ACCOUNT, ATTR_DEF_ADRESS, ATTR_DEF_CITY, ATTR_DEF_NAME, ATTR_DEF_POSTCODE, Acc_Tva\build(), Acc_Ledger\check_periode(), cn, db, Acc_Ledger\display_negative_warning(), Acc_Ledger\get_name(), h, Acc_Ledger\has_other_tax(), hb(), Anc_Plan\hidden(), Icon_Action\infobulle(), nbm(), noalyss_strlentrim(), span(), td(), tr(), UPDRECEIPT, and Acc_Ledger\warn_manual_receipt().

+ Here is the call graph for this function:

◆ input()

Acc_Ledger_Purchase::input ( $p_array = null,
$p_readonly = 0 )

display the form for entering data for invoice

Parameters
$p_arrayis null or you can put the predef operation or the $_POST
array
'sa' => string 'n' (length=1)
'p_action' => string 'ach' (length=3)
'gDossier' => string '28' (length=2)
'e_client' => string 'ASEKURA' (length=7)
'nb_item' => string '9' (length=1)
'p_jrn' => string '3' (length=1)
'period' => string '126' (length=3)
'e_comm' => string 'descriptio' (length=10)
'e_date' => string '01.05.2010' (length=10)
'e_ech' => string '' (length=0)
'jrn_type' => string 'ACH' (length=3)
'e_pj' => string 'ACH37' (length=5)
'e_pj_suggest' => string 'ACH37' (length=5)
'mt' => string '1273759434.5701' (length=15)
'e_mp' => string '0' (length=1)
'e_march0' => string 'DOC' (length=3)
'e_march0_price' => string '2000' (length=4)
'e_march0_tva_id' => string '3' (length=1)
'e_march0_tva_amount' => string '120' (length=3)
'e_quant0' => string '1' (length=1)
'gen_invoice' => string 'on' (length=2)
'gen_doc' => string '7' (length=1)
'bon_comm' => string '' (length=0)
'other_info' => string '' (length=0)
'correct' => string 'Corriger' (length=8)
Returns
HTML string

Reimplemented from Acc_Ledger.

Definition at line 1262 of file acc_ledger_purchase.class.php.

1263 {
1264 global $g_parameter,$g_user;
1265 // load ledger definition
1266 $this->load();
1267 $http=new HttpInput();
1268 if ( $p_array != null ) extract($p_array, EXTR_SKIP);
1269
1270 $flag_tva=$g_parameter->MY_TVA_USE;
1271
1272 /* Add button */
1273 $str_add_button_tiers = "";
1274 $add_card=FALSE;
1275 if ($g_user->check_action(FICADD) == 1) {
1276 $add_card=TRUE;
1277 $str_add_button_tiers = $this->add_card("cred", "e_client");
1278 }
1279 // The first day of the periode
1280 $oPeriode=new Periode($this->db);
1281 list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($g_user->get_periode());
1282 if ( $g_parameter->MY_DATE_SUGGEST=='Y' )
1283 $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
1284 else
1285 $op_date=( ! isset($e_date) ) ?'':$e_date;
1286
1287 $e_ech=(isset($e_ech))?$e_ech:"";
1288 $e_comm=(isset($e_comm))?$e_comm:"";
1289
1290 $r="";
1291 $r.=dossier::hidden();
1292 $f_legend_detail=_("Détail articles achetés");
1293
1294 // Date
1295 //--
1296 $Date=new IDate();
1297 $Date->setReadOnly(false);
1298 $Date->table=1;
1299 $Date->tabindex=1;
1300 $f_date=$Date->input("e_date",$op_date);
1301 // Payment limit
1302 //--
1303 $Echeance=new IDate();
1304 $Echeance->setReadOnly(false);
1305 $Echeance->tabindex=2;
1307 $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
1308 $f_periode="";
1309 if ($this->check_periode() == true)
1310 {
1311 // Periode
1312 //--
1313 $l_user_per=$g_user->get_periode();
1314 $def=(isset($periode))?$periode:$l_user_per;
1315
1316 $period=new IPeriod("period");
1317 $period->user=$g_user;
1318 $period->cn=$this->db;
1319 $period->value=$def;
1320 $period->type=OPEN;
1321 try
1322 {
1323 $l_form_per=$period->input();
1324 }
1325 catch (Exception $e)
1326 {
1327 record_log($e);
1328 if ($e->getCode() == 1 )
1329 {
1330 throw new Exception( _("Aucune période ouverte"));
1331 }
1332 }
1333
1334 $r.="<td>";
1336 $f_periode=td(_("Période comptable")." $label ").td($l_form_per);
1337 }
1338 // Ledger (p_jrn)
1339 //--
1340 /* if we suggest the next pj, then we need a javascript */
1341 $add_js="";
1342 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1343 {
1344 $add_js="update_receipt();";
1345 }
1346 if ($g_parameter->MY_DATE_SUGGEST == 'Y')
1347 {
1348 $add_js.='get_last_date();';
1349 }
1350 $add_js.='update_name();';
1351 $add_js.='update_pay_method();';
1352 $add_js.='update_row("sold_item");';
1353 $add_js.='update_other_tax();';
1354 $add_js.='update_visibility_quantity();';
1355
1356 $wLedger=$this->select_ledger('ACH',2,FALSE);
1357
1358 if ($wLedger == null) throw new Exception(_('Pas de journal disponible'));
1359 $wLedger->javascript="onChange='update_predef(\"ach\",\"f\",\"".$http->request("ac")."\");$add_js'";
1360 $wLedger->table=0;
1361 $f_jrn=$wLedger->input();
1362
1363 // Comment
1364 //--
1365 $Commentaire=new IText();
1366 $Commentaire->table=0;
1367 $Commentaire->setReadOnly(false);
1368 $Commentaire->size=60;
1369 $Commentaire->tabindex=3;
1371 $f_desc=$Commentaire->input("e_comm",$e_comm);
1372
1373 // PJ
1374 //--
1375 /* suggest PJ ? */
1376 $default_pj='';
1377 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1378 {
1379 $default_pj=$this->guess_pj();
1380 }
1381
1382 $pj=new IText();
1383 $pj->value=(isset($e_pj))?$e_pj:$default_pj;
1384
1385 if ( $g_parameter->MY_PJ_SUGGEST=='A' || $g_user->check_action(UPDRECEIPT)==0)
1386 {
1387 $pj->setReadOnly(true);
1388 $pj->id="e_pj";
1389 }
1390 $pj->table=0;
1391 $pj->name="e_pj";
1392 $pj->size=10;
1393 $pj->readonly=false;
1394
1395 $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
1396
1397 // Display the customer
1398 //--
1399 $fiche='cred';
1400
1401 // Save old value and set a new one
1402 //--
1403 $e_client=( isset ($e_client) )?$e_client:"";
1404 $e_client_label="&nbsp;";//str_pad("",100,".");
1405
1406
1407 // retrieve e_client_label
1408 //--
1409
1410 if ( noalyss_strlentrim($e_client) != 0)
1411 {
1412 $fClient=new Fiche($this->db);
1413 $fClient->get_by_qcode($e_client);
1414 $e_client_label=$fClient->get_attribute(ATTR_DEF_NAME).' '.
1415 ' Adresse : '.$fClient->get_attribute(ATTR_DEF_ADRESS).' '.
1416 $fClient->get_attribute(ATTR_DEF_POSTCODE).' '.
1417 $fClient->get_attribute(ATTR_DEF_CITY).' ';
1418
1419
1420 }
1421
1422 $W1=new ICard();
1423 $W1->label=_("Fournisseur ").Icon_Action::infobulle(0) ;
1424 $W1->name="e_client";
1425 $W1->tabindex=3;
1426 $W1->value=$e_client;
1427 $W1->table=0;
1428 $W1->set_dblclick("fill_ipopcard(this);");
1429 $W1->set_attribute('ipopup','ipopcard');
1430
1431 // name of the field to update with the name of the card
1432 $W1->set_attribute('label','e_client_label');
1433 // name of the field to update with the name of the card
1434 $W1->set_attribute('typecard','cred');
1435
1436 // Add the callback function to filter the card on the jrn
1437 $W1->set_callback('filter_card');
1438 $W1->set_function('fill_data');
1439 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1440 $W1->name);
1441 $f_client_qcode=$W1->input();
1442 $client_label=new ISpan();
1443 $client_label->style="vertical-align:top";
1444 $client_label->table=0;
1445 $f_client=$client_label->input("e_client_label",$e_client_label);
1446 $f_client_bt=$W1->search();
1447
1448
1449 // Record the current number of article
1450
1451 $e_comment=(isset($e_comment))?$e_comment:"";
1452 $p_article= ( isset ($nb_item))?$nb_item:$this->get_min_row();
1453 $p_article=($p_article < $this->get_min_row())?$this->get_min_row():$p_article;
1454
1455 $Hid=new IHidden();
1456 $r.=$Hid->input("nb_item",$p_article);
1457
1458 // For each article
1459 //--
1460 for ($i=0;$i< $p_article ;$i++)
1461 {
1462 // Code id, price & vat code
1463 //--
1464 $march=(isset(${"e_march$i"}))?${"e_march$i"}:"" ;
1465 $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
1466 ;
1467 /* use vat */
1468 if ( $g_parameter->MY_TVA_USE=='Y')
1469 {
1470 $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
1471 $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
1472 }
1473
1474
1475
1476 $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
1477 // retrieve the tva label and name
1478 //--
1479 if ( noalyss_strlentrim($march)!=0 && noalyss_strlentrim($march_label)==0 )
1480 {
1481 $fMarch=new Fiche($this->db);
1482 $fMarch->get_by_qcode($march);
1483 $march_label=$fMarch->get_attribute(ATTR_DEF_NAME);
1484 /* vat use */
1485 if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
1486 $march_tva_id=$fMarch->get_attribute(ATTR_DEF_TVA);
1487 }
1488 // Show input
1489 //--
1490 $W1=new ICard();
1491 $W1->label="";
1492 $W1->name="e_march".$i;
1493 $W1->value=$march;
1494 $W1->table=0;
1495 $W1->setAfter_clean("compute_all_ledger()");
1496 $W1->set_dblclick("fill_ipopcard(this);");
1497 $W1->set_attribute('ipopup','ipopcard');
1498
1499 $W1->set_attribute('typecard','deb');
1500
1501 // name of the field to update with the name of the card
1502 $W1->set_attribute('label','e_march'.$i.'_label');
1503 // name of the field with the price
1504 $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
1505 $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
1506
1507 // name of the field with the TVA_ID
1508 $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
1509 // Add the callback function to filter the card on the jrn
1510 $W1->set_callback('filter_card');
1511 $W1->set_function('fill_data');
1512 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1513 $W1->name);
1514 $W1->readonly=false;
1515 $array[$i]['quick_code']=$W1->input();
1516 $array[$i]['bt']=$W1->search();
1517 $array[$i]['card_add']=($add_card==TRUE)?$this->add_card("deb", $W1->id):"";
1518
1519 $array[$i]['hidden']='';
1520 // For computing we need some hidden field for holding the value
1521 if ( $g_parameter->MY_TVA_USE=='Y')
1522 {
1523 $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
1524 }
1525
1526 if ( $g_parameter->MY_TVA_USE=='Y')
1527 $tvac=new INum('tvac_march'.$i);
1528 else
1529 $tvac=new IHidden('tvac_march'.$i);
1530
1531 $tvac->readOnly=1;
1532 $tvac->value=0;
1533 $array[$i]['tvac']=$tvac->input();
1534
1535 $htva=new INum('htva_march'.$i);
1536 $htva->readOnly=1;
1537
1538 $htva->value=0;
1539 $array[$i]['htva']=$htva->input();
1540
1541 if ( $g_parameter->MY_UPDLAB == 'Y')
1542 {
1543 $Span=new IText("e_march".$i."_label");
1544 $Span->style='class="input_text label_item"';
1545 } else
1546 {
1547 $Span=new ISpan("e_march".$i."_label");
1548 $Span->extra='class="label_item"';
1549 }
1550 $Span->value=$march_label;
1551 $Span->setReadOnly(false);
1552 // card's name, price
1553 //--
1554 $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
1555 // price
1556 $Price=new INum();
1557 $Price->setReadOnly(false);
1558 $Price->size=9;
1559 $Price->javascript="onblur=\"format_number(this,4);clean_tva($i);compute_ledger($i)\"";
1560 $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
1561 if ( $g_parameter->MY_TVA_USE=='Y')
1562 {
1563
1564 // vat label
1565 //--
1566 $Tva=new ITva_Popup($this->db);
1567 $Tva->id="e_march$i"."_tva_id";
1568 $Tva->js="onblur=\"clean_tva($i);compute_ledger($i)\"";
1569 $Tva->in_table=true;
1570 $Tva->set_attribute('compute',$i);
1571 $Tva->set_filter("purchase");
1572 $Tva->value=$march_tva_id;
1573 $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
1574
1575 // Tva_amount
1576
1577 // price
1578 $Tva_amount=new INum();
1579 $Tva_amount->setReadOnly(false);
1580 $Tva_amount->size=9;
1581 $Tva_amount->javascript="onblur=\"format_number(this);compute_ledger($i)\"";
1582 $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
1583 }
1584 // quantity
1585 //--
1586 $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
1587 ;
1588 $Quantity=new INum();
1589 $Quantity->setReadOnly(false);
1590 $Quantity->size=9;
1591 $Quantity->javascript="onchange=\"format_number(this,2);clean_tva($i);compute_ledger($i)\"";
1592 $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
1593
1594 }
1595 $f_type=_('Fournisseur');
1596
1597 // Currency
1598 $currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
1599 $currency_select->selected=$http->request('p_currency_code','string',0);
1600
1601 $currency_input=new INum("p_currency_rate");
1602 $currency_input->prec=8;
1603 $currency_input->id="p_currency_rate";
1604 $currency_input->value=$http->request('p_currency_rate','string',1);
1605 $currency_input->javascript='onchange="format_number(this,6);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
1606
1607 $currency=new Acc_Currency($this->db,0);
1608
1609 //
1610 // Button for template operation
1611 //
1612 ob_start();
1613 echo '<div id="predef_form">';
1614 echo HtmlInput::hidden('p_jrn_predef', $this->id);
1615 $op = new Pre_operation($this->db);
1616 $op->set_p_jrn($this->id);
1617 $op->set_jrn_type("ACH");
1618 $op->set_od_direct('f');
1619 $url=http_build_query(array('p_jrn_predef'=>$this->id,'ac'=>$http->request('ac'),'gDossier'=>dossier::id()));
1620 echo $op->form_get('do.php?'.$url);
1621 echo '</div>';
1622 $str_op_template=ob_get_contents();
1623 ob_end_clean();
1624
1625 ob_start();
1626 require_once NOALYSS_TEMPLATE.'/form_ledger_detail.php';
1627 $r.=ob_get_contents();
1628 ob_end_clean();
1629
1630 // Set correctly the REQUEST param for jrn_type
1631 $r.= HtmlInput::hidden('jrn_type','ACH');
1633
1634
1635
1636 /* if we suggest the pj n# the run the script */
1637 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1638 {
1639 $r.='<script> update_receipt();</script>';
1640 }
1641 // set focus on date
1642 $r.= create_script("$('".$Date->id."').focus()");
1643 $r.='<div id="additional_tax_div">';
1644 $r.=$this->input_additional_tax();
1645 $r.='</div>';
1646 return $r;
1647 }
noalyss_strlentrim($p_string)
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
global $g_parameter
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
_("actif, passif,charge,...")
CurrencyInput($p_currency_code, $p_currency_rate, $p_eur_amount)
Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amou...
select_ledger($p_type="ALL", $p_access=3, $enable=TRUE)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
input_additional_tax()
form : display additional tax available for this ledger and value, set 2 values : checkbox if tax app...
add_card($p_filter, $p_id_update)
Return a button to create new card, depending of the ledger.
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
guess_pj()
guess what the next pj should be
static ledger_add_item($p_ledger)
Build a HTML string for adding multiple rows.
static hidden($p_name, $p_value, $p_id="")
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
$def
show a form for quick_writing
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
const ATTR_DEF_ADRESS
Definition constant.php:230
const OPEN
Definition constant.php:207
const ATTR_DEF_NAME
Definition constant.php:223
const ATTR_DEF_TVA
Definition constant.php:228
const ATTR_DEF_POSTCODE
Definition constant.php:231
const ATTR_DEF_CITY
Definition constant.php:236
const FICADD
const UPDRECEIPT
$oPeriode
Definition do.php:164
$SecUser db
create_script($p_string)
create the HTML for adding the script tags around of the script

References $array, $currency, Acc_Ledger\$db, $def, $e, $e_date, $fiche, $g_parameter, $g_user, $http, $i, $label, $op, $oPeriode, $p_array, $p_readonly, $periode, Acc_Ledger\$pj, $r, $url, $wLedger, _, Acc_Ledger\add_card(), ATTR_DEF_ADRESS, ATTR_DEF_CITY, ATTR_DEF_NAME, ATTR_DEF_POSTCODE, ATTR_DEF_TVA, Acc_Ledger\check_periode(), create_script(), Acc_Ledger\CurrencyInput(), db, FICADD, Acc_Ledger\get_min_row(), Acc_Ledger\guess_pj(), Icon_Action\infobulle(), Acc_Ledger\input_additional_tax(), Html_Input_Noalyss\ledger_add_item(), noalyss_strlentrim(), OPEN, record_log(), Acc_Ledger\select_ledger(), td(), and UPDRECEIPT.

+ Here is the call graph for this function:

◆ insert()

Acc_Ledger_Purchase::insert ( $p_array = null)

insert into the database, it calls first the verify function change the value of this->jr_id and this->jr_internal. It generates the document and save the middle of payment, if 'gen_invoice is set and e_mp

Parameters
$p_arrayis usually $_POST or a predefined operation
Array
(
[e_client] =>BELGACOM
[nb_item] =>9
[p_jrn] =>3
[period] =>117
[e_comm] =>Frais de téléphone
[e_date] =>01.09.2009
[e_ech] =>
[jrn_type] =>ACH
[e_pj] =>ACH53
[e_pj_suggest] =>ACH53
[mt] =>1265318941.39
[e_mp] =>0
[e_march0] =>TEL
[e_march0_price] =>63.6700
[e_march0_tva_id] =>1
[e_march0_tva_amount] =>13.3700
[e_quant0] =>1.000
...
[bon_comm] =>
[other_info] =>
[record] =>Enregistrement
[p_currency_code]=> id currency
[p_currency_rate]=>rate used
)
Returns
string
Note
throw an Exception

= e_pj then do not increment sequence , if the given receipt number is equal to one computed then increment

Definition at line 595 of file acc_ledger_purchase.class.php.

596 {
597 global $g_parameter,$g_user;
598 extract ($p_array, EXTR_SKIP);
599 $this->verify($p_array) ;
600 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
601 $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
602 $seq=$this->db->get_next_seq('s_grpt');
603 $this->id=$p_jrn;
604
605 $internal=$this->compute_internal_code($seq);
606 $this->jr_internal=$internal;
607
608 $cust=new Fiche($this->db);
609 $cust->get_by_qcode($e_client);
610 $sposte=$cust->get_attribute(ATTR_DEF_ACCOUNT);
611 // if 2 accounts, take only the credit Supplier
612 if ( strpos($sposte,',') != 0 )
613 {
614 $array=explode(',',$sposte);
615 $poste=$array[1];
616 }
617 else
618 {
619 $poste=$sposte;
620 }
621
622 $oPeriode=new Periode($this->db);
624
625 if ( $check_periode == true && isset($p_array['period']) )
626 $tperiode=$period;
627 else
628 $tperiode=$oPeriode->find_periode($e_date);
629
630
631 try
632 {
633 bcscale(4);
634 // variable : $tot_amount float : total amount of the purchase (debit)
635 $tot_amount=0;
636
637 // variable : $tot_tva float : total amount of the VAT
638 $tot_tva=0;
639
640 // variable: $tot_debit float : amount on debit side
641 $tot_debit=0;
642
643 $this->db->start();
644
645
646 // variable: $tot_tva_reversed float total VAT autoreverse, to deduce from supplier's amount
647 $tot_tva_reversed=0;
648
649 // variable : $tva array that will contain all the VAT Amount
650 $tva=array();
651
652 // variable : $tva_reverse array that contain all the VAT autoreverse AND negative
653 $tva_reverse = array();
654
655 // variable : $tva_reverse_credit array that contain all the VAT autoreverse for credit
656 $tva_reverse_credit = array();
657
658 // variable : $tot_amount_cur : total amount in currency
659 $tot_amount_cur=0;
660
661 // find the currency from v_currency_last_value
662 // variable : $currency_rate_ref Acc_Currency , currency object for this operation
663 $currency_rate_ref=new Acc_Currency($this->db, $p_currency_code);
664
665 /* Save all the items without vat and no deductible vat and expense*/
666 for ($i=0;$i< $nb_item;$i++)
667 {
668 if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
669
670 /* First we save all the items without vat */
671 $fiche=new Fiche($this->db);
672 $fiche->get_by_qcode(${"e_march".$i});
673 // variable : $tva_both integer 1 for autoreverse ,0 normal, fetch it once for this item,
674 $tva_both=0;
675 /* tva */
676 if ($g_parameter->MY_TVA_USE=='Y')
677 {
678 $idx_tva=trim(${'e_march'.$i.'_tva_id'});
679 $oTva=Acc_Tva::build($this->db,$idx_tva);
680
681 $oTva->load();
682 $tva_both=$oTva->get_parameter("both_side");
683 }
684 /* -- Create acc_operation -- */
685 $acc_operation=new Acc_Operation($this->db);
686 $acc_operation->date=$e_date;
687 $acc_operation->grpt=$seq;
688 $acc_operation->jrn=$p_jrn;
689 $acc_operation->type='d';
690 $acc_operation->periode=$tperiode;
691 $acc_operation->qcode="";
692 $amount_4=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
693
694 /* We have to compute all the amount thanks Acc_Compute */
695
696 $acc_amount=new Acc_Compute();
697 $acc_amount->check=false;
698 $acc_amount->set_parameter('amount',$amount_4);
699 // Set the currency rate
700 $acc_amount->set_parameter("currency_rate", $p_currency_rate);
701 $acc_amount->convert_euro();
702 $amount_euro=$acc_amount->amount;
703
704 // Compute VAT or take the given one
705 if ( $g_parameter->MY_TVA_USE=='Y')
706 {
707 $acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
708 if ( noalyss_strlentrim(${'e_march'.$i.'_tva_amount'}) ==0 || ${'e_march'.$i.'_tva_amount'} == 0)
709 {
710 // vat must computed and the amount is already converted to EUR
711 $acc_amount->compute_vat();
712
713 }
714 else
715 {
716 // we convert the vat in euro
717 $acc_amount->set_parameter("amount_vat", ${'e_march'.$i.'_tva_amount'});
718 $acc_amount->convert_euro_vat();
719
720 }
721 // convert amount in eur
722 $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
723 $tot_tva=round($tot_tva,2);
724 }
725
726
727 /* compute ND */
728 // variable: $save_amount_vat total float amount of VAT before changing due to NOT DEDUCTIBLE
729 $save_amount_vat=$acc_amount->amount_vat;
730 $this->compute_no_deductible($acc_amount, $fiche);
731 $acc_amount->correct();
732 // TVA which avoid
733 if ( $tva_both == 1 ) {
734 $acc_amount->autoreverse=$save_amount_vat;
735 $tot_tva_reversed=bcadd($tot_tva_reversed,$save_amount_vat);
736 }
737
738
739
740 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount),2);
741 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount_nd),2);
742 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount_perso),2);
743
744 /* get the account and explode if necessary */
745 $sposte=$fiche->get_attribute(ATTR_DEF_ACCOUNT);
746 // if 2 accounts, take only the debit one for customer
747 if ( strpos($sposte,',') != 0 )
748 {
749 $array=explode(',',$sposte);
750 $poste_val=$array[0];
751 }
752 else
753 {
754 $poste_val=$sposte;
755 }
756 if ($g_parameter->MY_UPDLAB=='Y')
757 {
758 $acc_operation->desc=strip_tags(${"e_march".$i."_label"}??"");
759 }
760 else
761 {
762 $acc_operation->desc="";
763 }
764 $acc_operation->poste=$poste_val;
765 $acc_operation->amount=$acc_amount->amount;
766 $acc_operation->qcode=${"e_march".$i};
767 if ($acc_amount->amount>0)
768 {
769 $tot_debit=bcadd($tot_debit, $acc_amount->amount);
770 }
771 $j_id=$acc_operation->insert_jrnx();
772
773 /* insert ND */
774 $this->insert_no_deductible($acc_amount, $fiche, $tva_both, $tot_debit,$acc_operation,$group,$i);
775
776
777 /* Compute sum vat */
778 if ( $g_parameter->MY_TVA_USE=='Y')
779 {
780 $tva_item=$acc_amount->amount_vat;
781
782 if ($tva_both == 0 ){
783 $tva[$idx_tva]=(isset( $tva[$idx_tva]))? $tva[$idx_tva]:0;
784 $tva[$idx_tva]=bcadd($tva[$idx_tva], $tva_item);
785 }else {
786 // $tva_item < 0 && $tva_both == 1
787 $tva_reverse[$idx_tva]=(isset($tva_reverse[$idx_tva]))?$tva_reverse[$idx_tva]:0;
788 $tva_reverse[$idx_tva]=bcadd($tva_item,$tva_reverse[$idx_tva]);
789 $tva_reverse_credit[$idx_tva]=(isset($tva_reverse_credit[$idx_tva]))?$tva_reverse_credit[$idx_tva]:0;
790 $tva_reverse_credit[$idx_tva]=bcadd($save_amount_vat,$tva_reverse_credit[$idx_tva]);
791 }
792 }
793 /* Save the stock */
794 /* if the quantity is < 0 then the stock increase (return of
795 * material)
796 */
797 $nNeg=(${"e_quant" . $i}< 0) ? -1 : 1;
798
799 // always save quantity but in withStock we can find
800 // what card need a stock management
801 if ( $g_parameter->MY_STOCK='Y'&& isset ($repo))
802 {
803 $dir=(${'e_quant'.$i} < 0 ) ? 'c':'d';
804 Stock_Goods::insert_goods($this->db,array('j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>$dir,'repo'=>$repo)) ;
805 }
806
807 if ( $g_parameter->MY_ANALYTIC != "nu" && $g_parameter->match_analytic($poste_val))
808 {
809 // for each item, insert into operation_analytique */
810 $op=new Anc_Operation($this->db);
811 $op->set_currency_rate($p_currency_rate);
812 $op->oa_group=$group;
813 $op->j_id=$j_id;
814 $op->oa_date=$e_date;
815 $op->oa_debit='t';
816 $op->oa_description=sql_string($e_comm);
817 $op->save_form_plan($p_array,$i,$j_id);
818 }
819 // insert into quant_purchase
820 //-----
821
822 if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0;
823 if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0;
824 if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0;
825 $price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
826
827 if ( $g_parameter->MY_TVA_USE=='Y')
828 {
829
830 $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
831 array(
832 null /*1*/
833 ,$j_id /* 2 */
834 ,${"e_march".$i} /* 3 */
835 ,${"e_quant".$i} /* 4 */
836 ,round($amount_euro,2) /* 5 */
837 ,$acc_amount->amount_vat /* 6 */
838 ,$oTva->get_parameter('id') /* 7 */
839 ,$acc_amount->amount_nd /* 8 */
840 ,$acc_amount->nd_vat /* 9 */
841 ,$acc_amount->nd_ded_vat /* 10 */
842 ,$acc_amount->amount_perso /* 11 */
843 ,$e_client /* 12 */
844 , $acc_amount->autoreverse /*13*/
845 ,$price_euro /* 14 */
846 ));
847
848
849 }
850 else
851 {
852 $acc_amount->amount_vat=0;
853 $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
854 array(
855 null /*1*/
856 ,$j_id /* 2 */
857 ,${"e_march".$i} /* 3 */
858 ,${"e_quant".$i} /* 4 */
859 ,round($acc_amount->amount,2) /* 5 */
860 ,0 /* 6 */
861 ,null/* 7 */
862 ,$acc_amount->amount_nd /* 8 */
863 ,0 /* 9 */
864 ,$acc_amount->nd_ded_vat /* 10 */
865 ,$acc_amount->amount_perso /* 11 */
866 ,$e_client /* 12 */
867 , $acc_amount->autoreverse /*13*/
868 ,$price_euro /* 14 */
869 ));
870 }
871 /*
872 * Insert also in operation_currency
873 */
874 $operation_currency=new Operation_currency_SQL($this->db);
875 $operation_currency->oc_amount=$acc_amount->amount_currency;
876 $operation_currency->oc_vat_amount=($tva_both==0)?$acc_amount->amount_vat_currency:0;
877 $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
878 $operation_currency->j_id=$j_id;
879 $operation_currency->insert();
880 $tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_currency,4),4);
881 $tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_vat_currency,4),4);
882 if ( DEBUGNOALYSS > 1 ) {
883 echo __LINE__." insert into operation currency oc_amount:{$acc_amount->amount_currency} oc_vat_amount {$acc_amount->amount_vat_currency} <br>";
884 }
885 } // end loop : save all items
886
887
888 /*** save other tax ****/
889 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
890 $row=$this->db->get_row("select ac_id,ac_label,ac_accounting
891 from acc_other_tax
892 where ac_id=$1 ",
893 [$p_array['other_tax']]);
894 if ( ! empty ($row )) {
895 $other_tax_amount=bcmul($p_array['other_tax_amount'],$p_currency_rate);
896 $acc_operation=new Acc_Operation($this->db);
897 $acc_operation->date=$e_date;
898 $acc_operation->poste=$row['ac_accounting'];
899 $acc_operation->amount=$other_tax_amount;
900 $acc_operation->grpt=$seq;
901 $acc_operation->jrn=$p_jrn;
902 $acc_operation->type='d';
903 $acc_operation->periode=$tperiode;
904 $acc_operation->desc=$row['ac_label'];
905 $jrn_tax_sql=new Jrn_Tax_SQL($this->db);
906 $jrn_tax_sql->j_id=$acc_operation->insert_jrnx();
907 $jrn_tax_sql->ac_id=$row['ac_id'];
908 $jrn_tax_sql->pcm_val=$row['ac_accounting'];
909 $jrn_tax_sql->insert();
910 $operation_currency=new Operation_currency_SQL($this->db);
911 $operation_currency->oc_amount=$p_array['other_tax_amount'];
912 $operation_currency->oc_vat_amount=0;
913 $operation_currency->oc_price_unit=0;
914 $operation_currency->j_id=$jrn_tax_sql->j_id;
915 $operation_currency->insert();
916
917 $tot_debit=bcadd($tot_debit, abs($other_tax_amount));
919 }
920
921 }
922
923
924 /*** save total customer ***/
925 if ( DEBUGNOALYSS > 1 ) {
926 echo __LINE__." tot_amount $tot_amount<br>";
927 echo __LINE__." tot_tva $tot_tva<br>";
928
929 }
930 $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
931 $acc_operation=new Acc_Operation($this->db);
932 $acc_operation->date=$e_date;
933 $acc_operation->poste=$poste;
934 $acc_operation->amount=bcsub($cust_amount,$tot_tva_reversed);
935 $acc_operation->grpt=$seq;
936 $acc_operation->jrn=$p_jrn;
937 $acc_operation->type='c';
938 $acc_operation->periode=$tperiode;
939 $acc_operation->qcode=${"e_client"};
940 if ($cust_amount<0)
941 {
942 $tot_debit=bcadd($tot_debit, abs($cust_amount));
943 }
944 $let_client=$acc_operation->insert_jrnx();
945
946 // --- insert also the currency amount for the customer
947 $operation_currency=new Operation_currency_SQL($this->db);
948 $operation_currency->oc_amount=$tot_amount_cur;
949 $operation_currency->oc_vat_amount=0;
950 $operation_currency->oc_price_unit=0;
951 $operation_currency->j_id=$let_client ;
952 $operation_currency->insert();
953
954 if ( $g_parameter->MY_TVA_USE=='Y')
955 {
956 /* save all vat
957 * $i contains the tva_id and value contains the vat amount
958 */
959 foreach ($tva as $i => $value)
960 {
961 $oTva=Acc_Tva::build($this->db,$i);
962 $poste_vat=$oTva->get_side('d');
963
964 $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
965 $acc_operation=new Acc_Operation($this->db);
966 $acc_operation->date=$e_date;
967 $acc_operation->poste=$poste_vat;
968 $acc_operation->amount=$value;
969 $acc_operation->grpt=$seq;
970 $acc_operation->jrn=$p_jrn;
971 $acc_operation->type='d';
972 $acc_operation->periode=$tperiode;
973 if ( $value > 0 ) $tot_debit=bcadd($tot_debit,abs($value));
974 $acc_operation->insert_jrnx();
975
976 } // LOOP : foreach $tva
977 foreach ($tva_reverse as $i => $value) {
978 $oTva = Acc_Tva::build($this->db,$i);
979 $poste_vat = $oTva->get_side('d');
980 if ( $poste_vat == '#')
981 {
982 $poste_vat=$oTva->get_side('c');
983 }
984
985 $acc_operation = new Acc_Operation($this->db);
986 $acc_operation->date = $e_date;
987 $acc_operation->poste = $poste_vat;
988 $acc_operation->amount = $value;
989 $acc_operation->grpt = $seq;
990 $acc_operation->jrn = $p_jrn;
991 $acc_operation->type = 'd';
992 $acc_operation->periode = $tperiode;
993
994 $acc_operation->insert_jrnx();
995
996 // if TVA is on both side, we deduce it immediately
997 // $x temp variable is the tva_reverse_account and will be used to check $poste_vat
998 $x=$oTva->get_parameter("tva_reverse_account");
999 $poste_vat =(trim($x??"")=="")? $oTva->get_side('c'):$x;
1000
1001 if ( $poste_vat == '#')
1002 {
1003 $poste_vat=$oTva->get_side('d');
1004 }
1005 $acc_operation = new Acc_Operation($this->db);
1006 $acc_operation->date = $e_date;
1007 $acc_operation->poste = $poste_vat;
1008 $acc_operation->amount = $tva_reverse_credit[$i];
1009 $acc_operation->grpt = $seq;
1010 $acc_operation->jrn = $p_jrn;
1011 $acc_operation->type = 'c';
1012 $acc_operation->periode = $tperiode;
1013 $acc_operation->insert_jrnx();
1014 $tot_debit = bcadd($tot_debit, $value);
1015 $tot_debit = round($tot_debit, 2);
1016 } //LOOP: foreach $tva_reverse
1017 }
1018
1019 /* insert into jrn */
1020 $acc_operation=new Acc_Operation($this->db);
1021 $acc_operation->date=$e_date;
1022 $acc_operation->echeance=$e_ech;
1023 // Total DEB
1024 $acc_operation->amount=$this->db->get_value("select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'",
1025 array($seq));
1026 $acc_operation->desc=$e_comm;
1027 $acc_operation->grpt=$seq;
1028 $acc_operation->jrn=$p_jrn;
1029 $acc_operation->periode=$tperiode;
1030 $acc_operation->pj=$e_pj;
1031 $acc_operation->mt=$mt;
1032 $acc_operation->currency_id=$p_currency_code;
1033 $acc_operation->currency_rate=$p_currency_rate;
1034 $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
1035
1036 if ( ! $this->jr_id=$acc_operation->insert_jrn() ) {
1037 throw new Exception (_("Erreur de balance"),EXC_BALANCE);
1038 }
1039 $this->pj=$acc_operation->update_receipt();
1040
1041 // Set Internal code
1042 $this->jr_grpt_id=$seq;
1043 $this->update_internal_code($internal);
1044 /* update quant_purchase */
1045 $this->db->exec_sql('update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
1046 array($internal,$seq));
1047
1048 /**= e_pj then do not increment sequence , if the given receipt number is equal to one computed then increment */
1049 if ($e_pj == $this->pj && noalyss_strlentrim($e_pj) != 0)
1050 {
1051 $this->inc_seq_pj();
1052 }
1053
1054 /* Save the attachment */
1055 if ( isset ($_FILES) && sizeof($_FILES) != 0 && $_FILES["pj"]["name"] != 0 )
1056 {
1057 $acc_document=new \Acc_Document($this->db, $this->jr_id);
1058 $acc_document->save_receipt();
1059 $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($_FILES['pj']['name']));
1060 }
1061 $str_file="";
1062 /* Generate an document and save it into the database (Note de frais only)
1063 */
1064 if ( isset($_POST['gen_invoice']) )
1065 {
1066 $ref_doc= $this->create_document($internal,$p_array);
1067 $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($ref_doc));
1068 }
1069
1070 //----------------------------------------
1071 // Save the payer
1072 //----------------------------------------
1073 if ( $e_mp != 0 )
1074 {
1075 /* mp */
1076 $mp=new Acc_Payment($this->db,$e_mp);
1077 $mp->load();
1078
1079 /* jrnx */
1080 $acseq=$this->db->get_next_seq('s_grpt');
1081 $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger_target'));
1082 $acinternal=$acjrn->compute_internal_code($acseq);
1083 /*
1084 * for the use of the card of the bank
1085 */
1086 if ( $acjrn->get_type()=='FIN') {
1087 $acjrn=new Acc_Ledger_Fin($this->db, $mp->get_parameter('ledger_target'));
1088 $acfiche=new Fiche($this->db,$acjrn->get_bank());
1089 $fqcode=$acfiche->get_attribute(ATTR_DEF_QUICKCODE);
1090 } else {
1091 $fqcode = ${'e_mp_qcode_' . $e_mp};
1092 $acfiche = new Fiche($this->db);
1093 $acfiche->get_by_qcode($fqcode);
1094 }
1095 /* Insert paid by */
1096 $acc_pay=new Acc_Operation($this->db);
1097 $acc_pay->date=$e_date;
1098
1099 /* get the account and explode if necessary */
1100 $sposte=$acfiche->get_attribute(ATTR_DEF_ACCOUNT);
1101 // if 2 accounts, take only the debit one for customer
1102 if ( strpos($sposte,',') != 0 )
1103 {
1104 $array=explode(',',$sposte);
1105 $poste_val=$array[1];
1106 }
1107 else
1108 {
1109 $poste_val=$sposte;
1110 }
1111 // remove the VAT autoliquidation
1112 $cust_amount=bcsub($cust_amount, $tot_tva_reversed);
1113
1114 // Convert paid amount in EUR
1115 $acompte_defcur=bcdiv($acompte, $p_currency_rate);
1116
1117 $famount=bcsub($cust_amount,$acompte_defcur);
1118
1119 $acc_pay->poste=$poste_val;
1120 $acc_pay->qcode=$fqcode;
1121 $acc_pay->amount=abs(round($famount,2));
1122 $acc_pay->desc='';
1123 $acc_pay->grpt=$acseq;
1124 $acc_pay->jrn=$mp->get_parameter('ledger_target');
1125 $acc_pay->periode=$tperiode;
1126 $acc_pay->type=($famount>=0)?'c':'d';
1127 $let_pay=$acc_pay->insert_jrnx();
1128
1129 /* Insert supplier */
1130 $acc_pay=new Acc_Operation($this->db);
1131 $acc_pay->date=empty($mp_date)?$e_date:$mp_date;
1132 $acc_pay->poste=$poste;
1133 $acc_pay->qcode=$e_client;
1134 $acc_pay->amount=abs(round($famount,2));
1135 $acc_pay->desc='';
1136 $acc_pay->grpt=$acseq;
1137 $acc_pay->jrn=$mp->get_parameter('ledger_target');
1138 $acc_pay->periode=$tperiode;
1139 $acc_pay->type=($famount>=0)?'d':'c';
1140 $let_other=$acc_pay->insert_jrnx();
1141
1142 // insert into operation_currency
1143 $operation_currency=new Operation_currency_SQL($this->db);
1144 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
1145 $operation_currency->oc_vat_amount=0;
1146 $operation_currency->oc_price_unit=0;
1147 $operation_currency->j_id=$let_other;
1148 $operation_currency->insert();
1149
1150 // insert into operation_currency bank
1151 $operation_currency=new Operation_currency_SQL($this->db);
1152 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
1153 $operation_currency->oc_vat_amount=0;
1154 $operation_currency->oc_price_unit=0;
1155 $operation_currency->j_id=$let_pay;
1156 $operation_currency->insert();
1157
1158 /* insert into jrn */
1159 $acc_pay->mt=$mt;
1160 $acc_pay->desc=(!isset($e_comm_paiement) || noalyss_strlentrim($e_comm_paiement) == 0) ?$e_comm:$e_comm_paiement;
1161
1162 // Add info for currency
1163 $acc_pay->currency_id=$p_currency_code;
1164 $acc_pay->currency_rate=$p_currency_rate;
1165 $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
1166
1167
1168 // insert into the table JRN
1169 $mp_jr_id=$acc_pay->insert_jrn();
1170 $this->payment_operation=$mp_jr_id;
1171 $acjrn->jr_grpt_id=$acseq;
1172 $acjrn->update_internal_code($acinternal);
1173 // add an automatic PJ if ODS
1174 if ($acjrn->get_type()=="ODS") {
1175 $acc_pay->pj=$acjrn->guess_pj();
1176 $acc_pay->update_receipt();
1177 }
1178 $r1=$this->get_id($internal);
1179 $r2=$this->get_id($acinternal);
1180
1181 /*
1182 * add lettering
1183 */
1184 $oletter=new Lettering($this->db);
1185 $oletter->insert_couple($let_client,$let_other);
1186
1187 /* set the flag paid */
1188 $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
1189
1190 /* Reconcialiation */
1191 $rec=new Acc_Reconciliation($this->db);
1192 $rec->set_jr_id($r1);
1193 $rec->insert($r2);
1194 /*
1195 * save also into quant_fin
1196 */
1197
1198 /* get ledger property */
1199 $ledger=new Acc_Ledger_Fin($this->db,$acc_pay->jrn);
1200 $prop=$ledger->get_propertie();
1201
1202 /* if ledger is FIN then insert into quant_fin */
1203 if ( $prop['jrn_def_type'] == 'FIN' )
1204 {
1205 $ledger->insert_quant_fin($acfiche->id,$mp_jr_id,$cust->id,bcmul($famount,-1),$let_other);
1206 }
1207
1208
1209 }
1210 /*----------------------------------------------
1211 * Save the note
1212 ----------------------------------------------*/
1213 if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
1214 $acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
1215 $acc_operation_note->setNote($p_array['jrn_note_input']);
1216 $acc_operation_note->setOperation_id( $this->jr_id);
1217 $acc_operation_note->save();
1218 }
1219 }//end try
1220 catch (Exception $e)
1221 {
1222 record_log($e);
1223 $this->db->rollback();
1224 throw $e;
1225 }
1226 $this->db->commit();
1227 return $internal;
1228 }
sql_string($p_string)
Fix the problem with the quote char for the database.
h( $row[ 'oa_description'])
$op jr_id
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
insert_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both, &$p_tot_debit, Acc_Operation $p_acc_operation, $p_group, $idx)
Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT.
compute_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche)
Compute the ND amount thanks the attribute of the concerned card.
inc_seq_pj()
increment the sequence for the pj
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value
create_document($internal, $p_array)
alias for Acc_Document->create_document
has_other_tax()
returns true if the ledger has an additional tax
update_internal_code($p_internal)
get_id($p_internal)
retrieve the jr_id thanks the internal code, do not change anything to the current object
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
static show_receipt_document($p_jr_id, $p_name="")
Returns HTML code for displaying a icon with a link to a receipt document from the ledger.
static insert_goods(&$p_cn, $p_array)
Insert into stock_goods from ACH and VEN.
$check_periode
$other_tax_amount
Definition compute.php:94
const EXC_BALANCE
Definition constant.php:362
const ATTR_DEF_QUICKCODE
Definition constant.php:244
const ATTR_DEF_ACCOUNT
Definition constant.php:222
$_POST['ac']
Definition do.php:323
$str_file

References $_POST, $acompte, $array, $check_periode, $e, $e_date, $fiche, $g_parameter, $g_user, $i, $j_id, $ledger, $op, $oPeriode, $other_tax_amount, $p_array, $p_jrn, $poste, $prop, $r, $repo, $Res, Acc_Ledger\$row, $seq, $str_file, $tot_amount, $value, $x, _, ATTR_DEF_ACCOUNT, ATTR_DEF_QUICKCODE, Acc_Tva\build(), Acc_Operation_Note\build_jrn_id(), Acc_Ledger\check_periode(), Acc_Ledger\compute_internal_code(), compute_no_deductible(), Acc_Ledger\create_document(), db, EXC_BALANCE, Acc_Ledger\get_id(), h, Acc_Ledger\has_other_tax(), Acc_Ledger\inc_seq_pj(), Stock_Goods\insert_goods(), insert_no_deductible(), jr_id, noalyss_strlentrim(), record_log(), sql_string(), and Acc_Ledger\update_internal_code().

+ Here is the call graph for this function:

◆ insert_no_deductible()

Acc_Ledger_Purchase::insert_no_deductible ( Acc_Compute $p_nd_amount,
Fiche $p_fiche,
$p_tva_both,
& $p_tot_debit,
Acc_Operation $p_acc_operation,
$p_group,
$idx )
private

Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT.

Parameters
Acc_Compute$p_nd_amountcontent ND amount
Fiche$p_ficheCard of the Service
type$p_tva_both0 if TVA is normal or 1 if on both side
type$p_tot_debittotal debit
$p_acc_operationAcc_Operation for inserting into jrnx
$p_groupgroup for AC
$idxrow number
See also
Acc_Ledger_Purchase\insert

Definition at line 419 of file acc_ledger_purchase.class.php.

420 {
421 global $g_parameter;
422 if ($p_acc_operation->jrnx_id == 0) {
423 throw new Exception(__FILE__.__LINE__.'invalid acc_operation.j_id');
424 }
425 $source_j_id=$p_acc_operation->jrnx_id ;
426 /*
427 * Save all the no deductible
428 * ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
429 */
430 if ($p_nd_amount->amount_nd_rate != 0)
431 {
432 $dna_default = new Acc_Parm_Code($this->db, 'DNA');
433
434 /* save op. */
435 if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
436 {
437 $dna = $p_fiche->get_attribute(ATTR_DEF_ACCOUNT_ND);
438 } else
439 {
440 $dna = $dna_default->p_value;
441 }
442 $dna = ($dna == '') ? $dna_default->p_value : $dna;
443
444 $p_acc_operation->type = 'd';
445 $p_acc_operation->amount = $p_nd_amount->amount_nd;
446 $p_acc_operation->poste = $dna;
447 $p_acc_operation->qcode = '';
448 $p_acc_operation->desc=$this->find_label($dna)." ND ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
449 if ($p_nd_amount->amount_nd > 0)
450 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_nd );
451 $j_id = $p_acc_operation->insert_jrnx();
452 }
453 /*
454 * ATTR_DEF_ACCOUNT_ND_PERSO
455 */
456 if ($p_nd_amount->amount_perso != 0)
457 {
458 $dna_default = new Acc_Parm_Code($this->db, 'DEP_PRIV');
459
460 /* save op. */
461 $p_acc_operation->type = 'd';
463 {
465 } else
466 {
467 $dna = $dna_default->p_value;
468 }
469 $dna = ($dna == '') ? $dna_default->p_value : $dna;
470
471 $p_acc_operation->amount = $p_nd_amount->amount_perso ;
472 $p_acc_operation->poste = $dna;
473 $p_acc_operation->qcode = '';
474 $p_acc_operation->desc=$this->find_label($dna)." ND_PRIV ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
475 if ($p_nd_amount->amount_perso> 0)
476 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
477 $j_id = $p_acc_operation->insert_jrnx();
478 }
479 if ($p_nd_amount->nd_vat != 0)
480 {
481 $dna_default = new Acc_Parm_Code($this->db, 'TVA_DNA');
482
483 /* save op. */
484 $p_acc_operation->type = 'd';
485 $p_acc_operation->qcode = '';
487 {
489 } else
490 {
491 $dna = $dna_default->p_value;
492 }
493 $dna = ($dna == '') ? $dna_default->p_value : $dna;
494
495 $p_acc_operation->amount = $p_nd_amount->nd_vat;
496 $p_acc_operation->poste = $dna;
497 $p_acc_operation->desc=$this->find_label($dna)." ND_TVA ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
498 $j_id = $p_acc_operation->insert_jrnx();
499 if ( $g_parameter->MY_ANALYTIC != "nu"
500 && $g_parameter->match_analytic($p_fiche->get_attribute(ATTR_DEF_ACCOUNT))
501 )
502 {
503 $op=new Anc_Operation($this->db);
504 $op->oa_group=$p_group;
505 $op->j_id=$j_id;
506 $op->oa_date=$p_acc_operation->date;
507
508 $op->oa_debit='t';
509 $op->oa_description=sql_string('ND_TVA');
510 $op->oa_jrnx_id_source=$source_j_id;
511 $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
512 }
513 if ($p_nd_amount->nd_vat> 0)
514 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_vat);
515
516 }
517 if ($p_nd_amount->nd_ded_vat != 0)
518 {
519 $dna_default = new Acc_Parm_Code($this->db, 'TVA_DED_IMPOT');
520 /* save op. */
522 {
523 $dna = $p_fiche->get_attribute(ATTR_DEF_ACCOUNT_ND_TVA);
524 } else
525 {
526 $dna = $dna_default->p_value;
527 }
528 $dna = ($dna == '') ? $dna_default->value : $dna;
529
530
531
532 $p_acc_operation->type = 'd';
533 $p_acc_operation->qcode = '';
534 $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
535 $p_acc_operation->poste = $dna;
536 $p_acc_operation->desc=$this->find_label($dna)." DED_TVA ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
537 if ($p_nd_amount->nd_ded_vat > 0)
538 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
539 $j_id = $p_acc_operation->insert_jrnx();
540 if ( $g_parameter->MY_ANALYTIC != "nu"
541 && $g_parameter->match_analytic($p_fiche->get_attribute(ATTR_DEF_ACCOUNT))
542 )
543 {
544 $op=new Anc_Operation($this->db);
545 $op->oa_group=$p_group;
546 $op->j_id=$j_id;
547 $op->oa_date=$p_acc_operation->date;
548
549 $op->oa_debit='t';
550 $op->oa_description=sql_string('DED_TVA ');
551 $op->oa_jrnx_id_source=$source_j_id;
552 $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_ded_vat);
553 }
554 }
555 }
find_label($p_value)
Retrieve the label of an accounting.
insert_jrnx()
Insert into the table Jrn The needed data are :
const ATTR_DEF_ACCOUNT_ND_TVA_ND
Definition constant.php:249
const ATTR_DEF_ACCOUNT_ND
Definition constant.php:251
const ATTR_DEF_ACCOUNT_ND_TVA
Definition constant.php:248
const ATTR_DEF_ACCOUNT_ND_PERSO
Definition constant.php:250

References $_POST, $g_parameter, $idx, $j_id, $op, ATTR_DEF_ACCOUNT, ATTR_DEF_ACCOUNT_ND, ATTR_DEF_ACCOUNT_ND_PERSO, ATTR_DEF_ACCOUNT_ND_TVA, ATTR_DEF_ACCOUNT_ND_TVA_ND, ATTR_DEF_QUICKCODE, db, Fiche\empty_attribute(), Acc_Ledger\find_label(), Fiche\get_attribute(), Acc_Operation\insert_jrnx(), and sql_string().

Referenced by insert().

+ Here is the call graph for this function:

◆ verify_operation()

Acc_Ledger_Purchase::verify_operation ( $p_array)

verify that the data are correct before inserting or confirming

Parameters
anarray (usually $_POST)
Returns
String
Exceptions
Exceptionif an error occurs

we have to check also if the different accountings exist "ATTR_DEF_DEP_PRIV" "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE" "ATTR_DEF_TVA_NON_DEDUCTIBLE" "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"

Reimplemented from Acc_Ledger.

Definition at line 129 of file acc_ledger_purchase.class.php.

130 {
131 global $g_parameter,$g_user;
132
133 if (is_array($p_array ) == false || empty($p_array))
134 throw new Exception ("Array empty");
135 /*
136 * Check needed value
137 */
138 check_parameter($p_array,'p_jrn,e_date,e_client');
139
140 extract ($p_array, EXTR_SKIP);
141 /* check if we can write into this ledger */
142 if ( $g_user->check_jrn($p_jrn) != 'W' )
143 throw new Exception (_('Accès interdit'),20);
144
145
146 /* check for a double reload */
147 if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
148 throw new Exception (_('Double Encodage'),5);
149
150 /* check if there is a customer */
151 if ( noalyss_strlentrim($e_client)== 0 )
152 throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
153
154 /* check if the date is valid */
155 if ( isDate($e_date) == null )
156 {
157 throw new Exception(_('Date invalide'), 2);
158 }
159 $oPeriode=new Periode($this->db);
160 if ( $this->check_periode() == false || ! isset($p_array['period']))
161 {
162 $tperiode=$oPeriode->find_periode($e_date);
163 }
164 else
165 {
166 $tperiode=$period;
167 $oPeriode->p_id=$tperiode;
168 /* check that the datum is in the choosen periode */
169 list ($min,$max)=$oPeriode->get_date_limit($tperiode);
170 if ( cmpDate($e_date,$min) < 0 ||
171 cmpDate($e_date,$max) > 0)
172 throw new Exception(_('Date et periode ne correspondent pas'),6);
173 }
174 /* check if the periode is closed */
175 if ( $this->is_closed($tperiode)==1 )
176 {
177 throw new Exception(_('Periode fermee'),6);
178 }
179
180 /* check if we are using the strict mode */
181 if( $this->check_strict() == true)
182 {
183 /* if we use the strict mode, we get the date of the last
184 operation */
185 $last_date=$this->get_last_date();
186 if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
187 throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
188 .$last_date._(' vous ne pouvez pas encoder à une '.
189 ' date antérieure dans ce journal'),13);
190
191 }
192
193 /* check the account */
194 $fiche=new Fiche($this->db);
195 $fiche->get_by_qcode($e_client);
196 if ($fiche->get_f_enable() == '0')
197 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"),$e_client), 50);
198
199 if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
200 throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
201
202
203
204 /* get the account and explode if necessary */
205 $sposte=$fiche->get_attribute(ATTR_DEF_ACCOUNT);
206 // if 2 accounts, take only the credit one for supplier
207 if ( strpos($sposte,',') != 0 )
208 {
209 $array=explode(',',$sposte);
210 $poste_val=$array[1];
211 }
212 else
213 {
214 $poste_val=$sposte;
215 }
216
217 /* The account exists */
218 $poste=new Acc_Account_Ledger($this->db,$poste_val);
219 if ( $poste->load() == false )
220 {
221 throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id.'] '._('n\'existe pas'),9);
222 }
223 /* Check if the card belong to the ledger */
224 $fiche=new Fiche ($this->db);
225 $fiche->get_by_qcode($e_client,'cred');
226 if ( $fiche->belong_ledger($p_jrn) !=1 )
227 throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
228
229 $nb=0;
230 //------------------------------------------------------
231 // The "Paid By" check
232 //------------------------------------------------------
233 if ($e_mp != 0 ) {
234 $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
235 // check for the currency , if we use a financial ledger and a card which is a bank account (with his own
236 // ledger , then the currency of the operation must be the same
237 $this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
238 }
239
240
241 //----------------------------------------
242 // foreach item
243 //----------------------------------------
244 for ($i=0;$i< $nb_item;$i++)
245 {
246 if ( noalyss_strlentrim(${'e_march'.$i})== 0) continue;
247
248 /* check if all card has a ATTR_DEF_ACCOUNT*/
249 $fiche=new Fiche($this->db);
250 $fiche->get_by_qcode(${'e_march'.$i});
251 if ($fiche->get_f_enable() == '0')
252 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"), ${'e_march' . $i}), 50);
253
254 /* check if amount are numeric and */
255 if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
256 throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide').' ['.${'e_march'.$i}.']',6);
257 if ( isNumber(${'e_quant'.$i}) == 0 )
258 throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide').' ['.${'e_quant'.$i}.']',7);
259
260 // Check if the given tva id is valid
261 if ( $g_parameter->MY_TVA_USE=='Y')
262 {
263 $tva_rate = Acc_Tva::build($this->db,${'e_march' . $i . '_tva_id'});
264 if ($tva_rate->tva_id == -1)
265 throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
266 $tva_rate->load();
267 /*
268 * check if the accounting for VAT are valid
269 */
270 $a_poste=explode(',',$tva_rate->tva_poste);
271
272 if (
273 $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1',array($a_poste[0])) == 0 )
274 throw new Exception(_(" La TVA ".$tva_rate->tva_label." utilise des postes comptables inexistants"));
275
276 }
277
278 if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
279 throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
280
281 /* get the account and explode if necessary */
282 $sposte=$fiche->get_attribute(ATTR_DEF_ACCOUNT);
283 // if 2 accounts, take only the debit
284 if ( strpos($sposte,',') != 0 )
285 {
286 $array=explode(',',$sposte);
287 $poste_val=$array[0];
288 }
289 else
290 {
291 $poste_val=$sposte;
292 }
293
294 /* The account exists */
295 $poste=new Acc_Account_Ledger($this->db,$poste_val);
296 if ( $poste->load() == false )
297 {
298 throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable').' ['.$poste->id._('n\'existe pas'),9);
299 }
300 /* Check if the card belong to the ledger */
301 $fiche=new Fiche ($this->db);
302 $fiche->get_by_qcode(${'e_march'.$i});
303 if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
304 throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
305 /**
306 * we have to check also if the different accountings exist
307 "ATTR_DEF_DEP_PRIV"
308 "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
309 "ATTR_DEF_TVA_NON_DEDUCTIBLE"
310 "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
311 */
312 foreach (array(
317 {
318 if ( ! $fiche->empty_attribute($key[0]) && $fiche->empty_attribute($key[2]))
319 {
320 $a=new Acc_Parm_Code($this->db,$key[1]);
321 if ( $this->db->count_sql('select pcm_val from tmp_pcmn where pcm_val=$1',array($a->p_value))==0)
322 throw new Exception ($key[1]._("ce code n'a pas de poste comptable, créez ce poste : [".$a->p_value."]"));
323 }
324 if ( ! $fiche->empty_attribute($key[0]) && ! $fiche->empty_attribute($key[2]))
325 {
326 $nd_str=$fiche->get_attribute($key[2]);
327 if ( $nd_str != '')
328 {
329 $poste_nd=new Acc_Account_Ledger($this->db,$nd_str);
330 if ( $poste_nd->load() == false)
331 {
332 $nd_msg=sprintf(_("Pour la fiche %s, le compte contrepartie %s n'existe pas"),
333 $fiche->getName(),$poste_nd->id);
334 $nd_msg=h($nd_msg);
335 throw new Exception ($nd_msg);
336 }
337 }
338 }
339 }
340 if ( ${"e_quant".$i} != 0 && trim(${"e_quant".$i}) !="" ) {$nb++;}
341 }
342
343 if ( $nb == 0 )
344 throw new Exception(_('Il n\'y a aucune marchandise'),12);
345
346 // check payment date
347 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == null) {
348 throw new Exception(_('Date de paiement invalide'),13);
349
350 }
351 // check that MP is in a not closed and exists
352 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == $mp_date ) {
353 $periode=new Periode($this->cn);
354 $periode->find_periode($mp_date);
355 $periode->set_ledger($this->id);
356 if ( $periode->is_closed() ) {
357 throw new Exception(_("Période fermée")." $mp_date ");
358 }
359
360 }
361 // check limit date
362 if ( isset ($e_ech) && trim ($e_ech)!="" && isDate($e_ech) == null )
363 {
364 throw new Exception(_('Date échéance invalide'),14);
365
366 }
367 // Check currency_rate if valid
368 if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
369 throw new Exception(_('Taux devise invalide'),15);
370 }
371 $this->check_currency_setting($p_currency_code);
372 }
isNumber($p_int)
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
catch(Exception $e) $tva_rate
for($i=0; $i< count($plan); $i++)( $j==0) $a_poste
$input_from cn
check_currency($p_qcode_payment, $p_currency_id)
When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo...
is_closed($p_periode)
check if the current ledger is closed
check_payment($e_mp, $e_mp_qcode)
check if the payment method is valid
get_last_date()
get the date of the last operation
check_strict()
Check if a Dossier is using the strict mode or not.
check_currency_setting($p_currency_code)
Check that the currency code does exist and the setting of the folder is correct.
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...

References $a, $a_poste, $array, $e_date, $fiche, $g_parameter, $g_user, $i, $max, $min, Acc_Ledger\$nb, $oPeriode, $p_array, $p_jrn, $periode, $poste, $tva_rate, _, ATTR_DEF_ACCOUNT, ATTR_DEF_ACCOUNT_ND, ATTR_DEF_ACCOUNT_ND_PERSO, ATTR_DEF_ACCOUNT_ND_TVA, ATTR_DEF_ACCOUNT_ND_TVA_ND, ATTR_DEF_DEP_PRIV, ATTR_DEF_DEPENSE_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP, Acc_Tva\build(), Acc_Ledger\check_currency(), Acc_Ledger\check_currency_setting(), check_parameter(), Acc_Ledger\check_payment(), Acc_Ledger\check_periode(), Acc_Ledger\check_strict(), cmpDate(), cn, db, Acc_Ledger\get_last_date(), h, Acc_Ledger\is_closed(), isDate(), isNumber(), and noalyss_strlentrim().

+ Here is the call graph for this function:

Field Documentation

◆ $payment_operation

Acc_Ledger_Purchase::$payment_operation
private

Definition at line 115 of file acc_ledger_purchase.class.php.


The documentation for this class was generated from the following file: