$b['jb_id']) ? 1 : -1; } $rowArray = array(); // Matrix of n elements (rows) and associative keys (cols) like row[0]['fieldName'] $sqlquery = ""; if ($supersetFieldString != "") : // ******************** // * ONLY HEADQUARTER * // ******************** if ($userTypeName == "hq") : // **** Selection of the customers for the list **** if ($f_exp_category == "1") : // Check for status-filter of the current row (new, modified, ...) $whereClause = ""; if ($f_status_filter == "1") : $whereClause = " AND cmp.cmp_modify_status = '1'"; endif; if ($f_status_filter == "2") : $whereClause = " AND cmp.cmp_modify_status = '2'"; endif; if ($f_status_filter == "3") : $whereClause = " AND (cmp.cmp_modify_status = '1' OR cmp.cmp_modify_status = '2')"; endif; // Filter // Export no cash payers if requested by global parameter if (EXPORT_FILTER_NO_CASHPAYER == "1" && CSC_ID_PAYER_CASH != "" && is_numeric(CSC_ID_PAYER_CASH)) : $whereClause .= " AND (isnull(cs.csc_id_payer) OR cs.csc_id_payer != '" . CSC_ID_PAYER_CASH . "')"; endif; // Export no debitors having an EID with LENGTH(EID) > 6 if (EXPORT_FILTER_EID_LENGTH != "" && is_numeric(EXPORT_FILTER_EID_LENGTH) && EXPORT_FILTER_EID_LENGTH > "0") : $whereClause .= " AND LENGTH(TRIM(cs.cs_eid)) <= " . EXPORT_FILTER_EID_LENGTH . " "; endif; if (mcIsSet($orderClause) == "") : $orderClause = "cmp.cmp_comp"; endif; $sqlquery = "SELECT " . $supersetFieldString . " FROM company AS cmp LEFT JOIN tax AS tx ON cmp.tx_id = tx.tx_id" . " LEFT JOIN branch AS br ON cmp.br_id = br.br_id," . " customer AS cs LEFT JOIN costcenter AS csc ON cs.csc_id = csc.csc_id" . " LEFT JOIN costcenteraddress AS cscad ON csc.csc_id = cscad.csc_id AND cscad.adt_id = '2'" . " LEFT JOIN address AS adre ON cscad.ad_id = adre.ad_id" . " LEFT JOIN headquarters AS hq ON cs.hq_id = hq.hq_id," . " employee AS emp, user AS usr, address AS ad" . " WHERE cmp.cmp_id = cs.cmp_id AND" . " cmp.cmp_type = '0' AND" . " cs.cs_eid != '' AND" . " cs.cs_admin = emp.emp_id AND" . " emp.usr_id = usr.usr_id AND" . " cmp.ad_id = ad.ad_id AND" . " usr.hq_id = $hq_id" . $whereClause . " ORDER BY " . $orderClause; /* $sqlquery = "SELECT " . $supersetFieldString . " FROM company AS cmp LEFT JOIN tax AS tx ON cmp.tx_id = tx.tx_id" . " LEFT JOIN branch AS br ON cmp.br_id = br.br_id," . " customer AS cs LEFT JOIN costcenter AS csc ON cs.csc_id = csc.csc_id" . " LEFT JOIN costcenteraddress AS cscad ON csc.csc_id = cscad.csc_id AND cscad.adt_id = '2'" . " LEFT JOIN address AS adre ON cscad.ad_id = adre.ad_id," . " employee AS emp, user AS usr, address AS ad" . " WHERE cmp.cmp_id = cs.cmp_id AND" . " cmp.cmp_type = '0' AND" . " cs.cs_eid != '' AND" . " cs.cs_admin = emp.emp_id AND" . " emp.usr_id = usr.usr_id AND" . " cmp.ad_id = ad.ad_id AND" . " usr.hq_id = $hq_id" . $whereClause . " ORDER BY " . $orderClause; */ $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $rowArray = convertRowToArray($result); endif; // **** Selection of the couriers for the list **** if ($f_exp_category == "2") : // Check for status-filter of the current row (new, modified, ...) $whereClause = ""; if ($f_status_filter == "1") : $whereClause = " AND cmp.cmp_modify_status = '1'"; endif; if ($f_status_filter == "2") : $whereClause = " AND cmp.cmp_modify_status = '2'"; endif; if ($f_status_filter == "3") : $whereClause = " AND (cmp.cmp_modify_status = '1' OR cmp.cmp_modify_status = '2')"; endif; // Export NO driver if defined if (EXPORT_FILTER_NO_DRIVER == "1") : $whereClause .= " AND (isnull(cr.cr_id_parent) OR cr.cr_id_parent = '0')"; endif; if (mcIsSet($orderClause) == "") : $orderClause = "cmp.cmp_comp"; endif; $sqlquery = "SELECT " . $supersetFieldString . " FROM company AS cmp, courier AS cr, user AS usr, address AS ad" . " WHERE cmp.cmp_id = cr.cmp_id AND" . " cr.usr_id = usr.usr_id AND" . " cmp.ad_id = ad.ad_id AND" . " usr.hq_id = $hq_id" . $whereClause . " ORDER BY " . $orderClause; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $rowArray = convertRowToArray($result); endif; // **** Selection of the vehicles for the list **** if ($f_exp_category == "3") : // Check for status-filter of the current row (new, modified, ...) $whereClause = ""; if ($f_status_filter == "1") : $whereClause = " AND crvh.crvh_modify_status = '1'"; endif; if ($f_status_filter == "2") : $whereClause = " AND crvh.crvh_modify_status = '2'"; endif; if ($f_status_filter == "3") : $whereClause = " AND (crvh.crvh_modify_status = '1' OR crvh.crvh_modify_status = '2' OR crvh.crvh_modify_status = '3')"; endif; if (mcIsSet($orderClause) == "") : $orderClause = "crvh.crvh_sid"; endif; $sqlquery = "SELECT " . $supersetFieldString . " FROM couriervehicle AS crvh, courier AS cr" . " LEFT JOIN courier AS cr_parent ON cr.cr_id_parent = cr_parent.cr_id " . " WHERE cr.cr_id = crvh.cr_id AND" . " cr.hq_id = $hq_id" . $whereClause . " ORDER BY " . $orderClause; $result = $db->query($sqlquery); if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage()); $rowArray = convertRowToArray($result); endif; // *************** // $f_exp_category == "5|6|7|8" will be routed to $f_exp_category == "4" // "5" : Export with jb_storno = "NULL|0|1|2" only // "6" : Export with jb_storno = "3" only // "7" : Export collected business volume ("current" cash flow) // "8" : Carrier business volume // *************** if ($f_exp_category >= "4" && $f_exp_category <= "8") : $fromClauseRelevantCostcenter = "jb.csc_id_payer"; // IMPORTANT !!!! ("jb.csc_id_payer", "jb.csc_id_related") // $fieldClausePriceFormular = $priceFormular; // IMPORTANT !!!! ("$priceFormular" id defined in "glob_defs.inc.php") $fieldClausePriceFormular = "jb.jb_totalprice"; // jb.jb_totalprice $fieldClauseCmpInv2Hq = "cmp2.cmp_inv2hq, "; // Invoice to headquarters before delivery to paying customer or directly to the customer $fieldClauseCmpSingleInvoice = "cmp2.cmp_inv2hq AS cmp_single_invoice, "; // One invoice for each job or not $fieldClauseCashMode = "jb.csc_id_payer AS cash, "; // CASH mode ("bar" or not) $fromClausePriceTable = "tourservice AS trs"; // IMPORTANT !!!! $priceTableAlias = "trs"; // IMPORTANT !!!! $whereClauseDatetimeField = "jb.jb_finishtime"; // IMPORTANT !!!! $whereClauseJbStatus = "jb.jb_status = '2'"; // IMPORTANT !!!! $whereClauseExportField = "jb.jb_export_time"; // IMPORTANT !!!! // !!!! $whereClauseExportField has to be defined before !!!! $whereClauseRelevantExportTime = " (ISNULL(" . $whereClauseExportField . ") OR (" . $whereClauseExportField . " = '0000-00-00 00:00:00')) AND "; // IMPORTANT !!!! $whereClauseIncomplete = " (ISNULL(jb.jb_incomplete) OR (jb.jb_incomplete = '0')) AND "; // IMPORTANT !!!! $whereClauseStorno = ""; $whereClausePrice = ""; $whereClauseFilterExport = ""; // Constants $constProductDescription = getParameterValue("0", "EXPORT_CONST_PRODUCT", $hq_id); if ($constProductDescription == "") : $constProductDescription = "K "; endif; $constPriceSpecial = getParameterValue("0", "EXPORT_CONST_PRICE_SPECIAL", $hq_id); if ($constPriceSpecial == "") : $constPriceSpecial = "FP"; endif; $constContactStaffer = getParameterValue("0", "EXPORT_CONST_STAFFER", $hq_id); if ($constContactStaffer == "") : $constContactStaffer = ""; endif; $constContactPerson = getParameterValue("0", "EXPORT_CONST_CONTACT_PERSON", $hq_id); if ($constContactPerson == "") : $constContactPerson = ""; endif; // Add fields for paying costcenter address data by parameter $parExportAddPayingCostcenteraddressDataAdt1 = getParameterValue("0", "EXPORT_ADD_PAYING_CSCAD_DATA_ADT_1", $hq_id); if ($parExportAddPayingCostcenteraddressDataAdt1 == "") : $parExportAddPayingCostcenteraddressDataAdt1 = getParameterValue("0", "EXPORT_ADD_PAYING_CSCAD_DATA_ADT_1", "0"); endif; $parExportAddPayingCostcenteraddressDataAdt2 = getParameterValue("0", "EXPORT_ADD_PAYING_CSCAD_DATA_ADT_2", $hq_id); if ($parExportAddPayingCostcenteraddressDataAdt2 == "") : $parExportAddPayingCostcenteraddressDataAdt2 = getParameterValue("0", "EXPORT_ADD_PAYING_CSCAD_DATA_ADT_2", "0"); endif; $parExportAddPayingCostcenteraddressDataAdt3 = getParameterValue("0", "EXPORT_ADD_PAYING_CSCAD_DATA_ADT_3", $hq_id); if ($parExportAddPayingCostcenteraddressDataAdt3 == "") : $parExportAddPayingCostcenteraddressDataAdt3 = getParameterValue("0", "EXPORT_ADD_PAYING_CSCAD_DATA_ADT_3", "0"); endif; // Add fields for master data company name and address by parameter $parExportAddCustomerMasterDataAddressAndCompanyName = getParameterValue("0", "EXPORT_ADD_CS_MASTER_DATA", $hq_id); if ($parExportAddCustomerMasterDataAddressAndCompanyName == "") : $parExportAddCustomerMasterDataAddressAndCompanyName = getParameterValue("0", "EXPORT_ADD_CS_MASTER_DATA", "0"); endif; endif; $useCategory4 = FALSE; if ($f_exp_category == "5") : $whereClauseStorno = " AND (isnull(jb.jb_storno) OR jb.jb_storno = '0' OR jb.jb_storno = '1') "; if ($specialJbPayment != "" && is_numeric($specialJbPayment)) : $whereClauseStorno .= " AND jb.jb_payment = '" . $specialJbPayment . "' "; else : $whereClauseStorno .= " AND jb.jb_payment IN ('0', '1', '2') "; endif; $whereClausePrice = " HAVING price > 0 "; $useCategory4 = TRUE; endif; if ($f_exp_category == "6") : $whereClauseStorno = " AND (isnull(jb.jb_storno) OR jb.jb_storno = '0' OR jb.jb_storno = '3') "; if ($specialJbPayment != "" && is_numeric($specialJbPayment)) : $whereClauseStorno .= " AND jb.jb_payment = '" . $specialJbPayment . "' "; else : $whereClauseStorno .= " AND jb.jb_payment IN ('0', '1', '2') "; endif; $whereClausePrice = " HAVING price < 0 "; $useCategory4 = TRUE; endif; if ($f_exp_category == "7") : $fromClauseRelevantCostcenter = "jb.csc_id_related"; $fieldClausePriceFormular = "SUM(jbp.jbp_price)"; $fromClausePriceTable = "jobpayment AS jbp"; $priceTableAlias = "jbp"; $whereClauseDatetimeField = "jbp.jbp_bookingtime"; // Redefine relevant datetime field. "jbp_bookingtime" ist the timestamp the endcustomer had paid $whereClauseJbStatus = "jb.jb_status IN ('0','1','2','8','9')"; // Redefine relevant job status $whereClauseExportField = "jbp.jbp_export_time"; // Redefine relevant export field // !!!! $whereClauseExportField has to be defined before !!!! $whereClauseRelevantExportTime = ""; // IMPORTANT !!!! (An job can be exported for generation debit and/or credit notes, but a credit note for an end customer can be created after this!) $whereClauseIncomplete = ""; // Job state "incomplete" is NOT relevant regarding the values paid by the endcustomer $whereClauseStorno = " AND (isnull(jb.jb_storno) OR jb.jb_storno = '0' OR jb.jb_storno = '1' OR jb.jb_storno = '3') "; // $whereClausePrice = " HAVING price > 0 "; $useCategory4 = TRUE; endif; if ($f_exp_category == "8") : // Constants $constProductDescription = getParameterValue("0", "EXPORT_CAT_08_CONST_PRODUCT", $hq_id); if ($constProductDescription == "") : $constProductDescription = "M3"; endif; $constPriceSpecial = getParameterValue("0", "EXPORT_CAT_08_CONST_PRICE_SPECIAL", $hq_id); if ($constPriceSpecial == "") : $constPriceSpecial = "FP"; endif; $constContactStaffer = getParameterValue("0", "EXPORT_CAT_08_CONST_STAFFER", $hq_id); if ($constContactStaffer == "") : $constContactStaffer = ""; endif; $constContactPerson = getParameterValue("0", "EXPORT_CAT_08_CONST_CONTACT_PERSON", $hq_id); if ($constContactPerson == "") : $constContactPerson = ""; endif; $constInvoiceToHeadquarters = getParameterValue("0", "EXPORT_CAT_08_CONST_INV2HQ", $hq_id); if ($constInvoiceToHeadquarters == "") : $constInvoiceToHeadquarters = "1"; endif; $constSingleInvoicePerJob = getParameterValue("0", "EXPORT_CAT_08_CONST_SINGLE_INV", $hq_id); if ($constSingleInvoicePerJob == "") : $constSingleInvoicePerJob = "2"; endif; // Clauses $fieldClauseCmpInv2Hq = "'" . $constInvoiceToHeadquarters . "' AS cmp_inv2hq, "; // Invoice to headquarters before delivery to paying customer in every case $fieldClauseCmpSingleInvoice = "'" . $constSingleInvoicePerJob . "' AS cmp_single_invoice, "; // One invoice for each job in every case $fieldClauseCashMode = "' ' AS cash, '0' AS jbpc_id, "; // CASH mode ("bar" or not) AND jbpc_id $fromClauseRelevantCostcenter = "jb.csc_id_related"; $whereClauseStorno = " AND (isnull(jb.jb_storno) OR jb.jb_storno = '0' OR jb.jb_storno = '1' OR jb.jb_storno = '3') "; $whereClauseStorno .= " AND jb.jb_cr_price > 0 "; if ($specialJbPayment != "" && is_numeric($specialJbPayment)) : $whereClauseStorno .= " AND jb.jb_payment = '" . $specialJbPayment . "' "; else : $whereClauseStorno .= " AND jb.jb_payment = '3' "; endif; $whereClauseStorno .= " AND EXISTS (SELECT * FROM jobpayment AS jbp2 WHERE jbp2.jb_id = jb.jb_id AND jbp2.jbpc_id != '0') "; $whereClauseStorno .= " AND (NOT isnull(jb.cr_id)) AND jb.cr_id != '0' "; $useCategory4 = TRUE; endif; // Filter for export according to calculator jobs ("sub-jobs") being credit notes $constFilterCalcNoBookingNote = getParameterValue("0", "EXPORT_FILTER_CALCULATOR_NO_BOOKINGNOTES", "0"); if ($constFilterCalcNoBookingNote == "1") : $whereClauseFilterExport = " AND ((isnull(jb.jb_id_parent) OR jb.jb_id_parent = '0' OR jb.jb_id_parent = '-1') OR (jb.jb_id_parent > '0' AND jb.jb_totalprice * jb2.jb_totalprice > 0))"; endif; // Selection of the invoices for the list // Only jobs WITH cr_id AND cr_sid will be exported !!! if ($f_exp_category == "4" || $useCategory4) : // Cash $select_clause = "SELECT jb.jb_id, " . "jb.cr_id, " . "jb.csc_id_related, " . "jb.hq_id_exec, " . "jb.hq_id_sales, " . "CONCAT(' ', RIGHT(jb.cr_sid, 3)) AS cr_sid, " . "cr_parent.cr_id AS cr_id_parent, " . "CONCAT(' ', RIGHT(cr_parent.cr_sid, 3)) AS cr_sid_parent, " . "CONCAT(SUBSTRING(jb.jb_ordertime, 1, 4), " . "SUBSTRING(jb.jb_ordertime, 6, 2), ". "SUBSTRING(jb.jb_ordertime, 9, 2)) AS orderdate, " . "SUBSTRING(jb.jb_ordertime, 12, 5) AS ordertime, " . "CONCAT(SUBSTRING(jb.jb_finishtime, 1, 4), " . "SUBSTRING(jb.jb_finishtime, 6, 2), ". "SUBSTRING(jb.jb_finishtime, 9, 2)) AS finishdate, " . "SUBSTRING(jb.jb_finishtime, 12, 5) AS finishtime, " . "'" . EXPORT_HQ_KEY . " ' AS cmp_no, " . "'" . $constProductDescription . "' AS prod_descr, " . "'" . $constContactStaffer . "' AS contact_staffer, " . "'" . $constContactPerson . "' AS contact_person, " . "' ' AS VAT_special, " . "RIGHT(cr.cr_eid, 5) AS cr_eid, " . "RIGHT(cr_parent.cr_eid, 5) AS cr_eid_parent, " . "jb.jb_invtext, " . "jb.jb_invtext_cr, " . "jb.jb_freetext_1, " . "jb.jb_freetext_2, " . "jb.jb_freetext_3, " . "jb.jb_postage, " . $fieldClauseCmpInv2Hq . $fieldClauseCmpSingleInvoice . $fieldClausePriceFormular . " AS price, " . "'" . $constPriceSpecial . "' AS price_special, " . $fieldClauseCashMode . "jb.jb_sales_tax_rate AS tax_rate, " . "jb.jb_sales_tax_rate_sign AS tax_rate_sign, " . "jb.vht_id, " . "jb.jb_cr_filter, " . "jb.jb_cr_filter_opt, " . "jb.jb_type, " . "jb.jb_longhaul, " . "jb.jb_longhaul_export, " . "jb.jb_id_parent, " . "(jb.jb_totalprice * 1.19) AS gross_price, " . "jb.jb_cr_price, " . "jb.jb_hq_id_exec_price, " . "jb.jb_subtotalprice, " . "jb.jb_markup, " . "jb.jb_cr_subprice, " . "'0' AS special_price_01, " . "'0' AS special_price_02, " . "jb.jb_tourdata, " . "jb.jb_service, " . "jb.jb_commission_no, " . "tr.tr_commission_no, " . "SUBSTRING_INDEX(jb.jb_tourdata, '|', -1) AS country_codes, " . "hq.hq_mnemonic, " . "cr_hq.hq_mnemonic AS cr_hq_mnemonic, " . "cr_parent_hq.hq_mnemonic AS cr_parent_hq_mnemonic, " . "'" . EXPORT_CONST_01 . "' AS const_01, " . "'" . EXPORT_CONST_02 . "' AS const_02, " . "'" . EXPORT_CONST_03 . "' AS const_03, " . "gdc_toll.gdc_content AS jb_toll, " . "gdc_third_country.gdc_content AS jb_third_country "; // Invoice $select_clause2 = $select_clause . ", " . "cs.cs_eid AS cs_eid1, " . "cs.cs_eid AS cs_eid2, " . "cs_hq.hq_mnemonic AS cs_hq_mnemonic, " . "cs.csc_id AS csc_id_root, " . "csc.csc_name "; if ($parExportAddPayingCostcenteraddressDataAdt1 == "1") : $select_clause2 .= ", " . "cscad1.cscad_comp AS cscad1_comp, " . "cscad1.cscad_comp2 AS cscad1_comp2, " . "cscad1.cscad_comp3 AS cscad1_comp3, " . "cscad1.cscad_comp4 AS cscad1_comp4, " . "ad_cscad1.ad_street AS ad_cscad1_street, " . "cscad1.cscad_hsno AS ad_cscad1_hsno, " . "ad_cscad1.ad_zipcode AS ad_cscad1_zipcode, " . "ad_cscad1.ad_city AS ad_cscad1_city "; endif; if ($parExportAddPayingCostcenteraddressDataAdt2 == "1") : $select_clause2 .= ", " . "cscad2.cscad_comp AS cscad2_comp, " . "cscad2.cscad_comp2 AS cscad2_comp2, " . "cscad2.cscad_comp3 AS cscad2_comp3, " . "cscad2.cscad_comp4 AS cscad2_comp4, " . "ad_cscad2.ad_street AS ad_cscad2_street, " . "cscad2.cscad_hsno AS ad_cscad2_hsno, " . "ad_cscad2.ad_zipcode AS ad_cscad2_zipcode, " . "ad_cscad2.ad_city AS ad_cscad2_city "; endif; if ($parExportAddPayingCostcenteraddressDataAdt3 == "1") : $select_clause2 .= ", " . "cscad3.cscad_comp AS cscad3_comp, " . "cscad3.cscad_comp2 AS cscad3_comp2, " . "cscad3.cscad_comp3 AS cscad3_comp3, " . "cscad3.cscad_comp4 AS cscad3_comp4, " . "ad_cscad3.ad_street AS ad_cscad3_street, " . "cscad3.cscad_hsno AS ad_cscad3_hsno, " . "ad_cscad3.ad_zipcode AS ad_cscad3_zipcode, " . "ad_cscad3.ad_city AS ad_cscad3_city "; endif; if ($parExportAddCustomerMasterDataAddressAndCompanyName == "1") : $select_clause2 .= ", " . "cmp2.cmp_comp AS cmp2_comp, " . "cmp2.cmp_comp2 AS cmp2_comp2, " . "cmp2.cmp_comp3 AS cmp2_comp3, " . "cmp2.cmp_comp4 AS cmp2_comp4, " . "ad_mstrdt.ad_street AS ad_mstrdt_street, " . "cmp2.cmp_hsno AS ad_mstrdt_hsno, " . "ad_mstrdt.ad_zipcode AS ad_mstrdt_zipcode, " . "ad_mstrdt.ad_city AS ad_mstrdt_city "; endif; // Cash $from_clause = "FROM headquarters AS hq, job AS jb " . " LEFT JOIN courier AS cr ON jb.cr_id=cr.cr_id " . " LEFT JOIN headquarters AS cr_hq ON cr.hq_id = cr_hq.hq_id " . " LEFT JOIN courier AS cr_parent ON cr.cr_id_parent = cr_parent.cr_id " . " LEFT JOIN headquarters AS cr_parent_hq ON cr_parent.hq_id = cr_parent_hq.hq_id " . " LEFT JOIN costcenter AS csc2 ON " . $fromClauseRelevantCostcenter . "=csc2.csc_id " . ($parExportAddPayingCostcenteraddressDataAdt1 == "1" ? " LEFT JOIN costcenteraddress AS cscad1 ON cscad1.csc_id=csc2.csc_id AND cscad1.adt_id='1' LEFT JOIN address AS ad_cscad1 ON ad_cscad1.ad_id=cscad1.ad_id " : "") . ($parExportAddPayingCostcenteraddressDataAdt2 == "1" ? " LEFT JOIN costcenteraddress AS cscad2 ON cscad2.csc_id=csc2.csc_id AND cscad2.adt_id='2' LEFT JOIN address AS ad_cscad2 ON ad_cscad2.ad_id=cscad2.ad_id " : "") . ($parExportAddPayingCostcenteraddressDataAdt3 == "1" ? " LEFT JOIN costcenteraddress AS cscad3 ON cscad3.csc_id=csc2.csc_id AND cscad3.adt_id='3' LEFT JOIN address AS ad_cscad3 ON ad_cscad3.ad_id=cscad3.ad_id " : "") . " LEFT JOIN customer AS cs2 ON cs2.cs_id=csc2.cs_id " . " LEFT JOIN company AS cmp2 ON cmp2.cmp_id=cs2.cmp_id " . ($parExportAddCustomerMasterDataAddressAndCompanyName == "1" ? " LEFT JOIN address AS ad_mstrdt ON ad_mstrdt.ad_id=cmp2.ad_id " : "") . " LEFT JOIN job AS jb2 ON jb.jb_id_parent=jb2.jb_id " . " LEFT JOIN tour AS tr ON tr.jb_id = jb.jb_id AND tr.tr_sort = '1' " . " LEFT JOIN address AS ad ON ad.ad_id = tr.ad_id " . " LEFT JOIN genericdatacontainer AS gdc_toll ON gdc_toll.gdc_obj_id = jb.jb_id AND gdc_toll.gdc_obj_type = 'jb' AND gdc_toll.gdc_gen_fieldname = 'jb_toll' " . " LEFT JOIN genericdatacontainer AS gdc_third_country ON gdc_third_country.gdc_obj_id = jb.jb_id AND gdc_third_country.gdc_obj_type = 'jb' AND gdc_third_country.gdc_gen_fieldname = 'jb_third_country', " . " " . $fromClausePriceTable . " "; // Invoice $from_clause2 = $from_clause . ", " . "costcenter AS csc, " . "customer AS cs, " . "headquarters AS cs_hq "; // Cash $where_clause = "WHERE jb.hq_id = '$hq_id' AND " . " jb.hq_id = hq.hq_id AND " . " (" . $whereClauseJbStatus . ") AND " . " (jb.csc_id_payer = '-1') AND " . $whereClauseRelevantExportTime . $whereClauseIncomplete . " (jb.jb_id = " . $priceTableAlias . ".jb_id) "; // Invoice $where_clause2 = "WHERE jb.hq_id = '$hq_id' AND " . " jb.hq_id = hq.hq_id AND " . " (" . $whereClauseJbStatus . ") AND " . " (jb.csc_id_payer != '-1') AND " . $whereClauseRelevantExportTime . $whereClauseIncomplete . " (jb.jb_id = " . $priceTableAlias . ".jb_id) AND "; // Change (end)customer data to related data (e.g. market) if ($fromClauseRelevantCostcenter == "jb.csc_id_payer") : $where_clause2 .= " (trs.csc_id = csc.csc_id AND csc.cs_id = cs.cs_id AND cs.hq_id = cs_hq.hq_id) "; elseif($fromClauseRelevantCostcenter == "jb.csc_id_related") : $where_clause2 .= " (jb.csc_id_related = csc.csc_id AND csc.cs_id = cs.cs_id AND cs.hq_id = cs_hq.hq_id) "; else : $where_clause2 .= " (" . $priceTableAlias . ".csc_id = csc.csc_id AND csc.cs_id = cs.cs_id AND cs.hq_id = cs_hq.hq_id) "; endif; // Filter export according to only one specified customer $f_status_filter_remember = ""; if ($f_cs_eid_filter != ""): $where_clause2 .= " AND (cs.cs_eid = '" . $f_cs_eid_filter . "') "; $f_status_filter_remember = $f_status_filter; $f_status_filter = "2"; // If customer is specified then only export invoice data and no cash data endif; // Filter export according specified vehicle types (if NO type is specified then this filter is not be used) $f_vht_filter_len = count($f_vht_filter); if ($f_vht_filter_len > 0) : $whereClauseFilterVehicleType = ""; for ($i = 0; $i < $f_vht_filter_len; $i++) : if ($whereClauseFilterVehicleType != "") : $whereClauseFilterVehicleType .= " OR "; endif; $whereClauseFilterVehicleType .= " cr.vht_id_inv = '" . $f_vht_filter[$i] . "'"; endfor; if ($whereClauseFilterVehicleType != "") : $whereClauseFilterVehicleType = " AND (" . $whereClauseFilterVehicleType . ") "; $where_clause .= $whereClauseFilterVehicleType; $where_clause2 .= $whereClauseFilterVehicleType; endif; endif; $goupby_clause = "GROUP BY " . $priceTableAlias . ".jb_id, " . $priceTableAlias . ".csc_id " . $whereClausePrice; // $priceTableAlias =!= "trs" by default $orderby_clause = "ORDER BY " . $priceTableAlias . ".jb_id, " . $priceTableAlias . ".csc_id "; // Only jobs WITH cr_id AND cr_sid // $where_clause .= " AND (NOT isnull(jb.cr_id)) AND jb.cr_id != '0' AND (NOT isnull(jb.cr_sid)) AND jb.cr_sid != '' "; // $where_clause2 .= " AND (NOT isnull(jb.cr_id)) AND jb.cr_id != '0' AND (NOT isnull(jb.cr_sid)) AND jb.cr_sid != '' "; // Storno and export filter $where_clause .= $whereClauseStorno . $whereClauseFilterExport; $where_clause2 .= $whereClauseStorno . $whereClauseFilterExport; // Date-range // "jb_finishtime" =