'; var_dump($v); echo ''; if ($die == true) die(); } function objectToArray($d) { if (is_object($d)) { // Gets the properties of the given object // with get_object_vars function $d = get_object_vars($d); } if (is_array($d)) { /* * Return array converted to object * Using __FUNCTION__ (Magic constant) * for recursive call */ return array_map(__FUNCTION__, $d); } else { // Return array return $d; } } $z=$db->query($query); $txt=""; while($dane=$db->fetchByAssoc($z)){ $p = new EcmProduct(); $p->retrieve($dane['product_id']); getConsignmentsDocs($dane['product_id'],$dane['stock_id'],$p->unit_id,$txt); } $fp = fopen('stanymagazynowe.csv', 'w'); echo $txt; fwrite($fp, $txt); fclose($fp); function getConsignmentsDocs($prod_id, $stock_id, $jm,&$txt) { $documents_map = array ( 'EcmStockDocIns' => 'PZ', 'EcmStockDocCorrects' => 'KS', 'EcmStockDocMoves' => 'MM', 'EcmStockDocInsideIns' => 'PW' ); global $db,$app_list_strings; $query = " select i.id, i.parent_id, i.parent_type,i.product_code,i.product_name, i.parent_name, i.price, i.quantity as in_qty, i.part_no, ifnull(sum(o.quantity),0) as out_qty, p.unit_id from ecmstockoperations as i left join ecmstockoperations as o on i.id = o.in_id inner join ecmproducts as p on i.product_id = p.id where i.product_id='$prod_id' and i.stock_id='$stock_id' and i.used = '0' and i.type='0' group by i.id order by i.date_entered;"; $res = $db->query ( $query ); $result = array (); global $app_list_strings, $sugar_config; while ( $row = $db->fetchByAssoc ( $res ) ) { $availability = (floatval ( $row ['in_qty'] ) - floatval ( $row ['out_qty'] )); if ($availability <= 0) continue; $tmp = array (); if($row ['parent_type'] == 'EcmStockDocInsideIns'){ $accountQuery = "SELECT name FROM ecmstockdocinsideins WHERE id='" . $row['parent_id'] . "'"; $accountResult = $db->query($accountQuery); if($accountResult->num_rows > 0){ $accountRow = $db->fetchByAssoc ( $accountResult ); $tmp ['account_name'] = $accountRow ['name']; }else{ $tmp ['account_name'] = ''; } }else{ $accountQuery = "SELECT parent_id, parent_name FROM " . strtolower($row ['parent_type']) ." WHERE id='" . $row['parent_id'] . "'"; $accountResult = $db->query($accountQuery); if($accountResult->num_rows > 0){ $accountRow = $db->fetchByAssoc ( $accountResult ); $tmp ['account_name'] = html_entity_decode($accountRow['parent_name']); }else{ $tmp ['account_name'] = ''; } } $tmp ['operation_id'] = $row ['id']; $tmp ['parent_name'] =$documents_map [$row ['parent_type']] . ' ' . $row ['parent_name']; $tmp ['part_no'] = $row['part_no']; $tmp ['availability'] = $availability; $tmp ['parent_id'] = $row ['parent_id']; $tmp ['parent_type'] = $row ['parent_type']; $tmp ['product_code'] = $row ['product_code']; $tmp ['product_name'] = $row ['product_name']; $tmp ['price'] = $row ['price']; $tmp ['unit'] = $app_list_strings ['ecmproducts_unit_dom'] [$row ['unit_id']]; $tmp ['currency'] = $sugar_config ['default_currency_iso4217']; $result [] = $tmp; } // number_format($tmp, 2, ",", ".") $html = '
Struktura zapasu
'; $s = new EcmStock(); $s->retrieve($stock_id); foreach($result as $key => $value){ $tmp = $value['availability']*$value['price']; $txt.='"=""'.iconv('UTF-8//IGNORE','windows-1250',preg_replace("/[^A-ZłŁąĄęĘżŻ,:@.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',$value['product_code'])) ).'""";'; $txt.= '"=""'.iconv('UTF-8//IGNORE','windows-1250',preg_replace("/[^A-ZłŁąĄęĘżŻ,:@.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',$value['product_name'] ))).'""";'; $txt.='"=""'.iconv('UTF-8//IGNORE','windows-1250',preg_replace("/[^A-ZłŁąĄęĘżŻ,:@.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',$value['parent_name']))) .'""";'; $txt.= '"=""'.iconv('UTF-8//IGNORE','windows-1250',preg_replace("/[^A-ZłŁąĄęĘżŻ,:@.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',$value['account_name']))) .'""";'; $txt.= '"=""'.$value['part_no'] .'""";'; $txt.= '"=""'.number_format($value['availability'], $app_list_strings['ecmproducts_unit_dom_precision'][$jm], ",", " ") .'""";'; //FormatNumber(c.availability) + ' ' + c.unit $txt.='"=""'.iconv('UTF-8//IGNORE','windows-1250',$value['unit']).'""";'; $txt.= '"=""'.number_format($value['price'], 2, ",", " ").'""";'; //FormatNumber(c.price) + ' ' + c.currency + ' / ' + c.unit $txt.= '"=""'.number_format($tmp, 2, ",", " ") .'""";'; $txt.='"=""'.iconv('UTF-8//IGNORE','windows-1250',preg_replace("/[^A-ZłŁąĄęĘżŻ,:@.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',$s->name))).'""";'.PHP_EOL; } } header("Location: stanymagazynowe.csv"); ?>
Dokument Dostawca/Nazwa dokumentu Partia Ilość Cena Wartość