Add php files
This commit is contained in:
73
modules/EcmReportsBackUp20151106/class/class.Account.php
Executable file
73
modules/EcmReportsBackUp20151106/class/class.Account.php
Executable file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Klasa pobiera informacje o właścicielu faktury
|
||||
* @author Krzysztof Raciniewski
|
||||
*
|
||||
*/
|
||||
class Account {
|
||||
|
||||
/**
|
||||
* Pobera wszystkie pozycje faktury o unikalnym ID
|
||||
*
|
||||
* @param $id -
|
||||
* unikalny ID faktury
|
||||
*/
|
||||
public static function getByAccountId($id) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "SELECT * FROM accounts WHERE id='$id'";
|
||||
$result = $db->query ( $query );
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Metoda stworzy strukturę tablicy:
|
||||
* .
|
||||
* .
|
||||
* |
|
||||
* |
|
||||
* +----- Kontrahent1 --------------------------+ Dokument1 ------------------> Wpisy na fakturze
|
||||
* | |
|
||||
* | |
|
||||
* | |
|
||||
* | +-------------------+ Dokument2 ------------------> Wpisy na fakturze
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* +----- Kontrahent2 --------------------------+ Kategoria ------------------> Wpisy na fakturze
|
||||
* . |
|
||||
* . |
|
||||
* . |
|
||||
* +-------------------+ Kategoria2 ------------------> Wpisy na fakturze
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* Na podstawie tablicy z dokumentami( taką tablicę zwraca metoda getBetweenDate w klasie Invoice i Receipt )
|
||||
* */
|
||||
public static function getAccountsFromInvoicesArray($invoices) {
|
||||
$accounts = array();
|
||||
|
||||
foreach( $invoices as $invoice ){
|
||||
$accounts[$invoice["parent_name"]]["invoices"][] = $invoice;
|
||||
}
|
||||
|
||||
return $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca w formie tablicy wszystkie wiersze odpowiedzi na zapytanie
|
||||
* @param $result
|
||||
* @return multitype:
|
||||
*/
|
||||
public static function getAllFromResult( $result ) {
|
||||
$itemsArray = array();
|
||||
|
||||
while($row = $result->fetch_assoc()){
|
||||
array_push($itemsArray, $row);
|
||||
}
|
||||
|
||||
return $itemsArray;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
51
modules/EcmReportsBackUp20151106/class/class.BuyerByVat.php
Executable file
51
modules/EcmReportsBackUp20151106/class/class.BuyerByVat.php
Executable file
@@ -0,0 +1,51 @@
|
||||
// <?php
|
||||
// /**
|
||||
// * @author: Katarzyna Zdunek
|
||||
// */
|
||||
// include ("class.BuyerItems.php");
|
||||
// class Buyer{
|
||||
|
||||
// public static function getById($id) {
|
||||
// $db = $GLOBALS ['db'];
|
||||
// $query = "SELECT * FROM documents WHERE id='$id'";
|
||||
// $result = $db->query ( $query );
|
||||
// $buyerData = $result->fetch_assoc ();
|
||||
// $buyerData ["items"] = InvoiceItems::getByBuyerId ( $id );
|
||||
// $buyerData ["account"] = Account::getByBuyerId ( $id );
|
||||
// return $buyerData;
|
||||
// }
|
||||
// /**
|
||||
// * Pobranie według daty
|
||||
// *
|
||||
// * **/
|
||||
// public static function getBetweenDate($date_from, $date_to, $category, $type, $contractorId) {
|
||||
// $db = $GLOBALS ['db'];
|
||||
|
||||
// $query = "SELECT * FROM documents
|
||||
// WHERE register_date
|
||||
// >= '$date_from' AND
|
||||
// register_date <= '$date_to'
|
||||
// AND type LIKE '$type' AND deleted=0 AND canceled=0 ";
|
||||
|
||||
// if (! empty ( $contractorId )) {
|
||||
// $query .= " AND parent_id = '" . $contractorId . "'";
|
||||
// }
|
||||
|
||||
// $query .= " ORDER BY date_entered asc";
|
||||
|
||||
// $result = $db->query ( $query );
|
||||
|
||||
// $buyersArray = array ();
|
||||
// while ( $buyerData = $result->fetch_assoc () ) {
|
||||
// // Formatowanie dat zgodnie z datÄ… systemowÄ…
|
||||
// $date = new DateTime ( $buyerData ["register_date"] );
|
||||
// $buyerData ["register_date"] = $date->format ( 'd.m.Y' );
|
||||
// $date = new DateTime ( $buyerData ["sell_date"] );
|
||||
// $buyerData ["sell_date"] = $date->format ( 'd.m.Y' );
|
||||
// $buyerData ["items"] = BuyerItems::getByBuyerId ( $buyerData ["id"] );
|
||||
// $buyerData ["account"] = Account::getByAccountId ( $buyerData ["parent_id"] );
|
||||
|
||||
|
||||
// }
|
||||
// }
|
||||
// ?>
|
||||
59
modules/EcmReportsBackUp20151106/class/class.Categories.php
Executable file
59
modules/EcmReportsBackUp20151106/class/class.Categories.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author raciniak
|
||||
*
|
||||
*/
|
||||
class Categories {
|
||||
|
||||
/**
|
||||
* Na wejściu przyjmuje itemy, zwraca tablicę kategorii
|
||||
*
|
||||
* Poniższa metoda stworzy strukturę tablicy:
|
||||
*
|
||||
*
|
||||
* |
|
||||
* |
|
||||
* +----- Kategoria1 --------------------------+ Wpis dokumentu1
|
||||
* | |
|
||||
* | |
|
||||
* | |
|
||||
* | +-------------------+ Wpis dokumentu2
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* +----- Kategoria2 --------------------------+ Wpis dokumentu3
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* +-------------------+ Wpis dokumentu4
|
||||
*
|
||||
* na podstawie tablicy wpisów dokumentu(items - w liście dokumentów zwracanych przez metodę getBetweenDate w klasie Invoice i Receipt)
|
||||
* */
|
||||
public static function categorizeItemsArray( $items ) {
|
||||
$categories = array();
|
||||
|
||||
foreach( $items as $item ) {
|
||||
$categoryName = Categories::getCategoryNameById( $item["ecmproductcategory_id"] );
|
||||
$categories[$categoryName] = $item;
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera nazwę kategorii na podstawie id
|
||||
* @param unknown $id
|
||||
*/
|
||||
public static function getCategoryNameById( $id ) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "select name from ecmproductcategories where id='$id'";
|
||||
$result = $db->query ( $query );
|
||||
$arrayResult = $result->fetch_assoc();
|
||||
$arrayResult["name"] == "" ? $name = "Inne" : $name = $arrayResult["name"];
|
||||
return $name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
215
modules/EcmReportsBackUp20151106/class/class.Invoice.php
Executable file
215
modules/EcmReportsBackUp20151106/class/class.Invoice.php
Executable file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
include ("class.InvoiceItems.php");
|
||||
|
||||
/**
|
||||
* Klasa reprezentuj<75>ca faktur<75>
|
||||
*
|
||||
* @author Krzysztof Raciniewski
|
||||
*
|
||||
*/
|
||||
class Invoice {
|
||||
|
||||
/**
|
||||
* Pobiera jeden dokument o unikalnym identyfikatorze ID
|
||||
*
|
||||
* @param $id -
|
||||
* identyfikator faktury
|
||||
*/
|
||||
public static function getById($id) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "SELECT * FROM ecminvoiceouts WHERE id='$id'";
|
||||
$result = $db->query($query);
|
||||
$invoiceData = $result->fetch_assoc();
|
||||
$invoiceData ["items"] = InvoiceItems::getByInvoiceId($id);
|
||||
$invoiceData ["account"] = Account::getByInvoiceId($id);
|
||||
return $invoiceData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera wszystkie dokumenty z podanego przedzia<69>u dat
|
||||
*
|
||||
* @param $date_from -
|
||||
* data od( w formacie YYYY-mm-dd )
|
||||
* @param $date_to -
|
||||
* data do( w formacie YYYY-mm-dd )
|
||||
* @param $type -
|
||||
* typ faktury(normal/correct)
|
||||
*/
|
||||
public static function getBetweenDate($date_from, $date_to, $pdf_type, $category, $type, $contractorId = FALSE, $stock_id = FALSE) {
|
||||
$db = $GLOBALS ['db'];
|
||||
global $app_list_strings;
|
||||
if ($_GET ['selectStock'] != "")
|
||||
$stock_id = $_GET['selectStock'];
|
||||
|
||||
|
||||
$query = "SELECT * FROM ecminvoiceouts
|
||||
WHERE register_date >= '$date_from'
|
||||
AND register_date <='$date_to'
|
||||
AND type LIKE '$type' AND deleted=0 AND canceled=0 ";
|
||||
|
||||
|
||||
if (!empty($contractorId) && $contractorId != "") {
|
||||
$query .= " AND parent_id = '" . $contractorId . "'";
|
||||
}
|
||||
|
||||
if (!empty($stock_id) && $stock_id != "") {
|
||||
$query .= " AND stock_id = '" . $stock_id . "' ";
|
||||
}
|
||||
|
||||
if (isset($pdf_type) && in_array(true, $pdf_type)) {
|
||||
$query .= ' AND pdf_type IN (';
|
||||
foreach ($pdf_type as $key => $value) {
|
||||
if ($value == true) {
|
||||
$query .= "'" . $key . "' ,";
|
||||
}
|
||||
}
|
||||
$query = rtrim($query, ",");
|
||||
$query .=") ";
|
||||
}
|
||||
|
||||
if (isset($category) && count($category) > 0 && count($category) != count($app_list_strings['ecminvoiceouts_category_dom'])) {
|
||||
if (in_array(" ", $category) && count($category) == 1) {
|
||||
$query .= " AND category IS NULL ";
|
||||
} else {
|
||||
if(in_array(" ", $category)){
|
||||
$query .= " AND category IS NULL ";
|
||||
}
|
||||
$query .= " AND category IN (";
|
||||
foreach ($category as $key => $value) {
|
||||
if ($value != " ") {
|
||||
$query .= "'" . $value . "' ,";
|
||||
}
|
||||
}
|
||||
$query = rtrim($query, ",");
|
||||
$query .=") ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$query .= " ORDER BY date_entered asc";
|
||||
|
||||
$result = $db->query($query);
|
||||
|
||||
$invoicesArray = array();
|
||||
while ($invoiceData = $result->fetch_assoc()) {
|
||||
// Formatowanie dat zgodnie z datą systemową
|
||||
$date = new DateTime($invoiceData ["register_date"]);
|
||||
$invoiceData ["register_date"] = $date->format('d.m.Y');
|
||||
$date = new DateTime($invoiceData ["sell_date"]);
|
||||
$invoiceData ["sell_date"] = $date->format('d.m.Y');
|
||||
$invoiceData ["items"] = InvoiceItems::getByInvoiceId($invoiceData ["id"]);
|
||||
$invoiceData ["account"] = Account::getByAccountId($invoiceData ["parent_id"]);
|
||||
|
||||
if ($type == "correct") {
|
||||
$invoiceData ["showType"] = "FVK";
|
||||
} else {
|
||||
$invoiceData ["showType"] = "FV";
|
||||
}
|
||||
|
||||
// Mnożę odpowiednie sumy przez currency_value
|
||||
Invoice::multiplyValuesByCurrencyValue($invoiceData);
|
||||
// Obliczam wysokość VAT i sumę netto
|
||||
$invoiceData ["netto0"] = Invoice::getNetto($invoiceData ["vats_summary"], "0%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["netto7"] = Invoice::getNetto($invoiceData ["vats_summary"], "7%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["netto8"] = Invoice::getNetto($invoiceData ["vats_summary"], "8%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["netto22"] = Invoice::getNetto($invoiceData ["vats_summary"], "22%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["netto23"] = Invoice::getNetto($invoiceData ["vats_summary"], "23%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
|
||||
$invoiceData ["vat0"] = Invoice::getVat($invoiceData ["vats_summary"], "0%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["vat7"] = Invoice::getVat($invoiceData ["vats_summary"], "7%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["vat8"] = Invoice::getVat($invoiceData ["vats_summary"], "8%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["vat22"] = Invoice::getVat($invoiceData ["vats_summary"], "22%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
$invoiceData ["vat23"] = Invoice::getVat($invoiceData ["vats_summary"], "23%", $invoiceData["currency_value"] != NULL ? $invoiceData["currency_value"] : $invoiceData["currency_value_nbp"]);
|
||||
|
||||
|
||||
// Jeżeli koszt własny na fakturze nie istnieje albo nulem
|
||||
if ($invoiceData ["purchase_price"] == NULL || $invoiceData ["purchase_price"] == "") {
|
||||
$invoiceData ["purchase_price"] = 0.00;
|
||||
}
|
||||
|
||||
// Wyliczam marżę dla faktury
|
||||
if ($type != "correct") {
|
||||
$invoiceData ["marginInPercent"] = ($invoiceData ['total_netto'] - $invoiceData ['purchase_price']) / ($invoiceData ['total_netto']) * 100;
|
||||
$invoiceData ["margin"] = $invoiceData ['total_netto'] - $invoiceData ['purchase_price'];
|
||||
} else {
|
||||
$invoiceData ["marginInPercent"] = 0;
|
||||
$invoiceData ["margin"] = 0;
|
||||
}
|
||||
|
||||
array_push($invoicesArray, $invoiceData);
|
||||
}
|
||||
|
||||
return $invoicesArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja mnoży wszystkie sumy przez currency_value o ile currency_value nie jest 0
|
||||
*
|
||||
* @param $data -
|
||||
* tablica danych przekazana jako referencja
|
||||
*/
|
||||
public static function multiplyValuesByCurrencyValue(&$data) {
|
||||
// Jeżeli kurs walutowy nie jest zerem ani pustym polem wtedy należy przemnożyć wszystkie wartości
|
||||
// bo wszystko musi być w złotówkach
|
||||
//echo 'currency_value_nbp: ' . $data["currency_value_nbp"] . '<br>';
|
||||
if ($data["currency_value"] != NULL && $data["currency_value"] != 0 && $data["currency_value"] != '') {
|
||||
$data["total_netto"] *= $data["currency_value"];
|
||||
$data["total_brutto"] *= $data["currency_value"];
|
||||
// $data["purchase_price"] *= $data["currency_value"];
|
||||
$data["margin"] *= $data["currency_value"];
|
||||
} elseif ($data["currency_value_nbp"] != NULL && $data["currency_value_nbp"] != 0 && $data["currency_value_nbp"] != '') {
|
||||
$data["total_netto"] *= $data["currency_value_nbp"];
|
||||
$data["total_brutto"] *= $data["currency_value_nbp"];
|
||||
// $data["purchase_price"] *= $data["currency_value_nbp"];
|
||||
$data["margin"] *= $data["currency_value_nbp"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja wyciąga netto z bazy( w bazie zapisane jest to w formacie: 23%:2000.00:460.00:2460.00 )
|
||||
* @param unknown $formatted_string
|
||||
* @param unknown $param_vat
|
||||
* @param unknown $currency_value
|
||||
* @return Ambigous <NULL, unknown>
|
||||
*/
|
||||
public static function getNetto($formatted_string, $param_vat, $currency_value) {
|
||||
$return = NULL;
|
||||
$vats = explode(",", $formatted_string);
|
||||
foreach ($vats as $vat) {
|
||||
$split_values = explode(":", $vat);
|
||||
if ($split_values[0] == $param_vat) {
|
||||
// Ceny na itemach wymagają przemnożenia przez kurs walutowy
|
||||
($currency_value == NULL || $currency_value == "") ? $currency_value = 1 : $currency_value = $currency_value;
|
||||
$return = $split_values[1] * $currency_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja wyciąga vat z bazy( w bazie zapisane jest to w formacie: 23%:2000.00:460.00:2460.00 )
|
||||
* @param unknown $formatted_string
|
||||
* @param unknown $param_vat
|
||||
* @param unknown $currency_value
|
||||
* @return Ambigous <NULL, unknown>
|
||||
*/
|
||||
public static function getVat($formatted_string, $param_vat, $currency_value) {
|
||||
$return = NULL;
|
||||
$vats = explode(",", $formatted_string);
|
||||
foreach ($vats as $vat) {
|
||||
$split_values = explode(":", $vat);
|
||||
if ($split_values[0] == $param_vat) {
|
||||
// Ceny na itemach wymagają przemnożenia przez kurs walutowy
|
||||
($currency_value == NULL || $currency_value == "") ? $currency_value = 1 : $currency_value = $currency_value;
|
||||
$return = $split_values[2] * $currency_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
35
modules/EcmReportsBackUp20151106/class/class.InvoiceItems.php
Executable file
35
modules/EcmReportsBackUp20151106/class/class.InvoiceItems.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Klasa reprezentuj<75>ca wpis na fakturze
|
||||
* @author Krzysztof Raciniewski
|
||||
*
|
||||
*/
|
||||
class InvoiceItems {
|
||||
|
||||
/**
|
||||
* Pobera wszystkie pozycje faktury o unikalnym ID
|
||||
* @param $id - unikalny ID faktury
|
||||
*/
|
||||
public static function getByInvoiceId( $id ) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "SELECT * FROM ecminvoiceoutitems WHERE ecminvoiceout_id='$id'";
|
||||
$result = $db->query ( $query );
|
||||
|
||||
return InvoiceItems::getAllFromResult( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca w formie tablicy wszystkie wiersze odpowiedzi na zapytanie
|
||||
* @param unknown $result
|
||||
* @return multitype:
|
||||
*/
|
||||
public static function getAllFromResult( $result ) {
|
||||
$itemsArray = array();
|
||||
while($row = $result->fetch_assoc()){
|
||||
array_push($itemsArray, $row);
|
||||
}
|
||||
return $itemsArray;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
39
modules/EcmReportsBackUp20151106/class/class.InvoicesHelper.php
Executable file
39
modules/EcmReportsBackUp20151106/class/class.InvoicesHelper.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
include("class.Invoice.php");
|
||||
include("class.Receipt.php");
|
||||
include ("class.Account.php");
|
||||
/**
|
||||
* Klasa statyczna odpowiedzialna za wyciąganie z bazy
|
||||
* informacji związanych z fakturami
|
||||
* @author Krzysztof Raciniewski
|
||||
*
|
||||
*/
|
||||
class InvoicesHelper {
|
||||
|
||||
/**
|
||||
* Metoda pobiera fakturę o odpowiednim ID w formie tabeli
|
||||
* zwraca wszystkie możliwe pola z bazy danych
|
||||
* @param $id - Identyfikator faktury
|
||||
*/
|
||||
public static function getInvoiceById( $id ) {
|
||||
return Invoice::getById( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca list<73> faktur, które były dodane w podanym zakresie dat
|
||||
* @param $date_from - data startowa
|
||||
* @param $date_to - data końcowa
|
||||
* @param $type - typ faktury(normal/correct)
|
||||
*/
|
||||
public static function getInvoicesBetweenDates( $date_from, $date_to, $pdf_type, $category, $type = "%", $contractorId ) {
|
||||
return Invoice::getBetweenDate( $date_from, $date_to, $pdf_type, $category, $type, $contractorId );
|
||||
}
|
||||
|
||||
public static function getReceiptsBetweenDates( $date_from, $date_to, $type = "%", $contractorId ) {
|
||||
return Receipt::getBetweenDate( $date_from, $date_to, $type, $contractorId );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
183
modules/EcmReportsBackUp20151106/class/class.PurchaseInvoice.php
Executable file
183
modules/EcmReportsBackUp20151106/class/class.PurchaseInvoice.php
Executable file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
include ("class.PurchaseInvoiceItems.php");
|
||||
|
||||
/**
|
||||
* Klasa reprezentuj<75>ca faktur<75>
|
||||
*
|
||||
* @author Kate
|
||||
*
|
||||
*/
|
||||
class Invoice {
|
||||
|
||||
/**
|
||||
* Pobiera jeden dokument o unikalnym identyfikatorze ID
|
||||
*
|
||||
* @param $id -
|
||||
* identyfikator faktury
|
||||
*/
|
||||
public static function getById($id) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "SELECT * FROM documents d LEFT OUTER JOIN documents_vat dv on d.id= dv.document_id WHERE d.id='$id'";
|
||||
$result = $db->query ( $query );
|
||||
$invoiceData = $result->fetch_assoc ();
|
||||
$invoiceData ["items"] = PurchaseInvoiceItems::getByInvoiceId ( $id );
|
||||
$invoiceData ["account"] = Account::getByInvoiceId ( $id );
|
||||
return $invoiceData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera wszystkie dokumenty z podanego przedzia<69>u dat
|
||||
*
|
||||
* @param $date_from -
|
||||
* data od( w formacie YYYY-mm-dd )
|
||||
* @param $date_to -
|
||||
* data do( w formacie YYYY-mm-dd )
|
||||
* @param $type -
|
||||
* typ faktury(normal/correct)
|
||||
*/
|
||||
public static function getBetweenDate($date_from, $date_to, $category, $contractorId) {
|
||||
$db = $GLOBALS ['db'];
|
||||
|
||||
$query = "SELECT * FROM documents
|
||||
WHERE register_date >= '$date_from'
|
||||
AND register_date <='$date_to'
|
||||
AND register_date IS NOT NULL
|
||||
AND register_date >= STR_TO_DATE('01.01.1990', '%d.%m.%Y')
|
||||
AND register_date <= STR_TO_DATE('01.01.2515', '%d.%m.%Y')
|
||||
AND deleted=0
|
||||
AND canceled=0
|
||||
AND sdocument_number IS NOT NULL
|
||||
";
|
||||
|
||||
if (! empty ( $contractorId )) {
|
||||
$query .= " AND parent_id = '" . $contractorId . "'";
|
||||
}
|
||||
|
||||
|
||||
if( count( $category ) != 0 && $category[0] != "%" ) {
|
||||
for( $i = 0; $i < count($category); $i++ ) {
|
||||
if( $i == 0) {
|
||||
$query .= " AND category = '".$category[$i]."'";
|
||||
} else {
|
||||
$query .= " OR category = '".$category[$i]."'";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query .= " ORDER BY rgister_date asc";
|
||||
|
||||
$result = $db->query ( $query );
|
||||
|
||||
$invoicesArray = array ();
|
||||
while ( $invoiceData = $result->fetch_assoc () ) {
|
||||
// Formatowanie dat zgodnie z datą systemową
|
||||
$date = new DateTime ( $invoiceData ["register_date"] );
|
||||
$invoiceData ["register_date"] = $date->format ( 'd.m.Y' );
|
||||
$date = new DateTime ( $invoiceData ["document_date"] );
|
||||
$invoiceData ["document_date"] = $date->format ( 'd.m.Y' );
|
||||
$invoiceData ["items"] = PurchaseInvoiceItems::getByInvoiceId ( $invoiceData ["id"] );
|
||||
$invoiceData ["account"] = Account::getByAccountId ( $invoiceData ["parent_id"] );
|
||||
|
||||
|
||||
// Mnożę odpowiednie sumy przez currency_value
|
||||
Invoice::multiplyValuesByCurrencyValue ( $invoiceData );
|
||||
|
||||
// Obliczam wysokość VAT i sumę netto
|
||||
$invoiceData ["netto0"] = Invoice::getNetto ( $invoiceData ["vats_summary"], "0%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["netto7"] = Invoice::getNetto ( $invoiceData ["vats_summary"], "7%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["netto8"] = Invoice::getNetto ( $invoiceData ["vats_summary"], "8%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["netto22"] = Invoice::getNetto ( $invoiceData ["vats_summary"], "22%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["netto23"] = Invoice::getNetto ( $invoiceData ["vats_summary"], "23%", $invoiceData["currency_value"]);
|
||||
|
||||
$invoiceData ["vat0"] = Invoice::getVat ( $invoiceData ["vats_summary"], "0%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["vat7"] = Invoice::getVat ( $invoiceData ["vats_summary"], "7%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["vat8"] = Invoice::getVat ( $invoiceData ["vats_summary"], "8%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["vat22"] = Invoice::getVat ( $invoiceData ["vats_summary"], "22%", $invoiceData["currency_value"]);
|
||||
$invoiceData ["vat23"] = Invoice::getVat ( $invoiceData ["vats_summary"], "23%", $invoiceData["currency_value"]);
|
||||
|
||||
|
||||
// Jeżeli koszt własny na fakturze nie istnieje albo nulem
|
||||
if ($invoiceData ["purchase_price"] == NULL || $invoiceData ["purchase_price"] == "") {
|
||||
$invoiceData ["purchase_price"] = 0.00;
|
||||
}
|
||||
|
||||
// Wyliczam marżę dla faktury
|
||||
// if ($type != "correct") {
|
||||
// $invoiceData ["marginInPercent"] = ($invoiceData ['total_netto'] - $invoiceData ['purchase_price']) / ($invoiceData ['total_netto']) * 100;
|
||||
// $invoiceData ["margin"] = $invoiceData ['total_netto'] - $invoiceData ['purchase_price'];
|
||||
// } else {
|
||||
// $invoiceData ["marginInPercent"] = 0;
|
||||
// $invoiceData ["margin"] = 0;
|
||||
// }
|
||||
|
||||
array_push ( $invoicesArray, $invoiceData );
|
||||
}
|
||||
|
||||
return $invoicesArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja mnoży wszystkie sumy przez currency_value o ile currency_value nie jest 0
|
||||
*
|
||||
* @param $data -
|
||||
* tablica danych przekazana jako referencja
|
||||
*/
|
||||
public static function multiplyValuesByCurrencyValue(&$data) {
|
||||
// Jeżeli kurs walutowy nie jest zerem ani pustym polem wtedy należy przemnożyć wszystkie wartości
|
||||
// bo wszystko musi być w złotówkach
|
||||
if( $data["currency_value"] != NULL && $data["currency_value"] != 0 && $data["currency_value"] != '') {
|
||||
$data["total_netto"] *= $data["currency_value"];
|
||||
$data["total_brutto"] *= $data["currency_value"];
|
||||
$data["purchase_price"] *= $data["currency_value"];
|
||||
$data["margin"] *= $data["currency_value"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja wyciąga netto z bazy( w bazie zapisane jest to w formacie: 23%:2000.00:460.00:2460.00 )
|
||||
* @param unknown $formatted_string
|
||||
* @param unknown $param_vat
|
||||
* @param unknown $currency_value
|
||||
* @return Ambigous <NULL, unknown>
|
||||
*/
|
||||
public static function getNetto($formatted_string, $param_vat, $currency_value) {
|
||||
$return = NULL;
|
||||
$vats = explode( ";" , $formatted_string);
|
||||
foreach( $vats as $vat ) {
|
||||
$split_values = explode( ":" , $vat );
|
||||
if( $split_values[0] == $param_vat ) {
|
||||
// Ceny na itemach wymagają przemnożenia przez kurs walutowy
|
||||
($currency_value == NULL || $currency_value == "") ? $currency_value = 1 : $currency_value = $currency_value;
|
||||
$return = $split_values[1] * $currency_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja wyciąga vat z bazy( w bazie zapisane jest to w formacie: 23%:2000.00:460.00:2460.00 )
|
||||
* @param unknown $formatted_string
|
||||
* @param unknown $param_vat
|
||||
* @param unknown $currency_value
|
||||
* @return Ambigous <NULL, unknown>
|
||||
*/
|
||||
public static function getVat($formatted_string, $param_vat, $currency_value) {
|
||||
$return = NULL;
|
||||
$vats = explode( ";" , $formatted_string);
|
||||
foreach( $vats as $vat ) {
|
||||
$split_values = explode( ":" , $vat );
|
||||
if( $split_values[0] == $param_vat ) {
|
||||
// Ceny na itemach wymagają przemnożenia przez kurs walutowy
|
||||
($currency_value == NULL || $currency_value == "") ? $currency_value = 1 : $currency_value = $currency_value;
|
||||
$return = $split_values[2] * $currency_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
36
modules/EcmReportsBackUp20151106/class/class.PurchaseInvoiceH.php
Executable file
36
modules/EcmReportsBackUp20151106/class/class.PurchaseInvoiceH.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
include ("class.Account.php");
|
||||
include ("class.PurchaseInvoice.php");
|
||||
/**
|
||||
* Klasa statyczna odpowiedzialna za wyciąganie z bazy
|
||||
* informacji związanych z fakturami
|
||||
* @author Kate
|
||||
*/
|
||||
class PurchaseInvoice {
|
||||
|
||||
/**
|
||||
* Metoda pobiera fakturę o odpowiednim ID w formie tabeli
|
||||
* zwraca wszystkie możliwe pola z bazy danych
|
||||
* @param $id - Identyfikator faktury
|
||||
*/
|
||||
public static function getInvoiceById( $id ) {
|
||||
return PurchaseInvoice::getById( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca list<73> faktur, które były dodane w podanym zakresie dat
|
||||
* @param $date_from - data startowa
|
||||
* @param $date_to - data końcowa
|
||||
* @param $type - typ faktury(normal/correct)
|
||||
*/
|
||||
public static function getInvoicesBetweenDates( $date_from, $date_to, $category, $contractorId ) {
|
||||
return PurchaseInvoice::getBetweenDate( $date_from, $date_to, $category, $contractorId );
|
||||
}
|
||||
|
||||
// public static function getReceiptsBetweenDates( $date_from, $date_to, $type = "%", $contractorId ) {
|
||||
// return Receipt::getBetweenDate( $date_from, $date_to, $type, $contractorId );
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
43
modules/EcmReportsBackUp20151106/class/class.PurchaseInvoiceItems.php
Executable file
43
modules/EcmReportsBackUp20151106/class/class.PurchaseInvoiceItems.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: Katarzyna Zdunek
|
||||
**/
|
||||
|
||||
class PurchaseInvoiceItems{
|
||||
/**
|
||||
* Pobiera wszystkie faktury wchodzące do firmy
|
||||
* @param id- unikalny id faktury wchodzacej
|
||||
*
|
||||
**/
|
||||
public static function getByInvoiceId($id)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
$query = "SELECT * FROM Documents WHERE parent_id'=$id'
|
||||
AND parent_type= 'Accounts'
|
||||
AND (category_id= 'invoice_costs'
|
||||
OR category_id= 'invoice_goods')";
|
||||
$result = $db->query($query);
|
||||
|
||||
return BuyerItems::getAllFromResult ($result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Zwrocenie w tablicy wszystkich wynik<69>w zapytania
|
||||
*
|
||||
* @param $result wiersze w postaci tablicy
|
||||
*/
|
||||
public static function getAllFromResult ($result){
|
||||
$itemsArray= Array();
|
||||
while ( $row = $result->fetch_assoc () ) {
|
||||
array_push ( $itemsArray, $row );
|
||||
}
|
||||
return $itemsArray;
|
||||
}
|
||||
}
|
||||
echo"<pre>";
|
||||
print_r($data);
|
||||
echo"</pre>";
|
||||
?>
|
||||
147
modules/EcmReportsBackUp20151106/class/class.Receipt.php
Executable file
147
modules/EcmReportsBackUp20151106/class/class.Receipt.php
Executable file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
include ("class.ReceiptItems.php");
|
||||
|
||||
/**
|
||||
* Klasa reprezentująca paragon
|
||||
*
|
||||
* @author Krzysztof Raciniewski
|
||||
*
|
||||
*/
|
||||
class Receipt {
|
||||
|
||||
/**
|
||||
* Pobiera jeden paragon o unikalnym identyfikatorze ID
|
||||
*
|
||||
* @param $id -
|
||||
* identyfikator paragonu
|
||||
*/
|
||||
public static function getById($id) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "SELECT * FROM ecmreceipts WHERE id='$id'";
|
||||
$result = $db->query ( $query );
|
||||
$receiptData = $result->fetch_assoc ();
|
||||
$receiptData ["items"] = ReceiptItems::getByReceiptId ( $id );
|
||||
$receiptData ["account"] = Account::getByInvoiceId ( $id );
|
||||
return $receiptData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera wszystkie paragony z podanego przedziału dat
|
||||
*
|
||||
* @param $date_from -
|
||||
* data od( w formacie YYYY-mm-dd )
|
||||
* @param $date_to -
|
||||
* data do( w formacie YYYY-mm-dd )
|
||||
* @param $type -
|
||||
* typ paragonu(normal/correct)
|
||||
*/
|
||||
public static function getBetweenDate($date_from, $date_to, $type, $contractorId) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "SELECT * FROM ecmreceipts
|
||||
WHERE date_entered >= '$date_from'
|
||||
AND date_entered <='$date_to'
|
||||
AND type LIKE '$type' AND deleted=0 ";
|
||||
|
||||
if (! empty ( $contractorId )) {
|
||||
$query .= " AND parent_id = '" . $contractorId . "'";
|
||||
}
|
||||
|
||||
$result = $db->query ( $query );
|
||||
|
||||
$receiptsArray = array ();
|
||||
while ( $receiptData = $result->fetch_assoc () ) {
|
||||
// Formatowanie dat zgodnie z datą systemową
|
||||
$date = new DateTime ( $receiptData ["register_date"] );
|
||||
$receiptData ["register_date"] = $date->format ( 'd.m.Y' );
|
||||
$date = new DateTime ( $receiptData ["sell_date"] );
|
||||
$receiptData ["sell_date"] = $date->format ( 'd.m.Y' );
|
||||
$receiptData ["items"] = ReceiptItems::getByReceiptId ( $receiptData ["id"] );
|
||||
$receiptData ["account"] = Account::getByAccountId ( $receiptData ["parent_id"] );
|
||||
|
||||
// Mnożę odpowiednie sumy przez currency_value
|
||||
Invoice::multiplyValuesByCurrencyValue ( $receiptData );
|
||||
|
||||
// Obliczam wysokość VAT i sumę netto
|
||||
$receiptData ["netto0"] = Receipt::getNetto ( $receiptData ["vats_summary"], "0%", $receiptData["currency_value"]);
|
||||
$receiptData ["netto7"] = Receipt::getNetto ( $receiptData ["vats_summary"], "7%", $receiptData["currency_value"]);
|
||||
$receiptData ["netto8"] = Receipt::getNetto ( $receiptData ["vats_summary"], "8%", $receiptData["currency_value"]);
|
||||
$receiptData ["netto22"] = Receipt::getNetto ( $receiptData ["vats_summary"], "22%", $receiptData["currency_value"]);
|
||||
$receiptData ["netto23"] = Receipt::getNetto ( $receiptData ["vats_summary"], "23%", $receiptData["currency_value"]);
|
||||
|
||||
$receiptData ["vat0"] = Receipt::getVat ( $receiptData ["vats_summary"], "0%", $receiptData["currency_value"]);
|
||||
$receiptData ["vat7"] = Receipt::getVat ( $receiptData ["vats_summary"], "7%", $receiptData["currency_value"]);
|
||||
$receiptData ["vat8"] = Receipt::getVat ( $receiptData ["vats_summary"], "8%", $receiptData["currency_value"]);
|
||||
$receiptData ["vat22"] = Receipt::getVat ( $receiptData ["vats_summary"], "22%", $receiptData["currency_value"]);
|
||||
$receiptData ["vat23"] = Receipt::getVat ( $receiptData ["vats_summary"], "23%", $receiptData["currency_value"]);
|
||||
|
||||
// Wyliczam marżę dla paragonu( nie ma to chyba sensu, ale ... :D )
|
||||
$receiptData["margin"] = ($receiptData['total_netto'] - $receiptData['purchase_price'])/($receiptData['total_netto'])*100;
|
||||
|
||||
if ($type == "correct") {
|
||||
$receiptData ["showType"] = "PRK";
|
||||
$receiptData ["marginInPercent"] = 0;
|
||||
$receiptData ["margin"] = 0;
|
||||
} else {
|
||||
$receiptData ["showType"] = "PR";
|
||||
$receiptData ["marginInPercent"] = ($receiptData ['total_netto'] - $receiptData ['purchase_price']) / ($receiptData ['total_netto']) * 100;
|
||||
$receiptData ["margin"] = $receiptData ['total_netto'] - $receiptData ['purchase_price'];
|
||||
}
|
||||
|
||||
// Jeżeli koszt własny na fakturze jest zerem albo nulem
|
||||
if ($receiptData ["purchase_price"] == NULL || $receiptData ["purchase_price"] == "") {
|
||||
$receiptData ["purchase_price"] = "0.00";
|
||||
}
|
||||
array_push ( $receiptsArray, $receiptData );
|
||||
}
|
||||
|
||||
return $receiptsArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Funkcja wyciąga netto z bazy( w bazie zapisane jest to w formacie: 23%:2000.00:460.00:2460.00 )
|
||||
* @param unknown $formatted_string
|
||||
* @param unknown $param_vat
|
||||
* @param unknown $currency_value
|
||||
* @return Ambigous <NULL, unknown>
|
||||
*/
|
||||
public static function getNetto($formatted_string, $param_vat, $currency_value) {
|
||||
$return = NULL;
|
||||
$vats = explode( ";" , $formatted_string);
|
||||
foreach( $vats as $vat ) {
|
||||
$split_values = explode( ":" , $vat );
|
||||
if( $split_values[0] == $param_vat ) {
|
||||
// Ceny na itemach wymagają przemnożenia przez kurs walutowy
|
||||
($currency_value == NULL || $currency_value == "") ? $currency_value = 1 : $currency_value = $currency_value;
|
||||
$return = $split_values[1] * $currency_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja wyciąga vat z bazy( w bazie zapisane jest to w formacie: 23%:2000.00:460.00:2460.00 )
|
||||
* @param unknown $formatted_string
|
||||
* @param unknown $param_vat
|
||||
* @param unknown $currency_value
|
||||
* @return Ambigous <NULL, unknown>
|
||||
*/
|
||||
public static function getVat($formatted_string, $param_vat, $currency_value) {
|
||||
$return = NULL;
|
||||
|
||||
$vats = explode( ";" , $formatted_string);
|
||||
foreach( $vats as $vat ) {
|
||||
$split_values = explode( ":" , $vat );
|
||||
if( $split_values[0] == $param_vat ) {
|
||||
// Ceny na itemach wymagają przemnożenia przez kurs walutowy
|
||||
($currency_value == NULL || $currency_value == "") ? $currency_value = 1 : $currency_value = $currency_value;
|
||||
$return = $split_values[2] * $currency_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
39
modules/EcmReportsBackUp20151106/class/class.ReceiptItems.php
Executable file
39
modules/EcmReportsBackUp20151106/class/class.ReceiptItems.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Klasa reprezentująca wpis na paragonie
|
||||
* @author Krzysztof Raciniewski
|
||||
*
|
||||
*/
|
||||
class ReceiptItems {
|
||||
|
||||
/**
|
||||
* Pobera wszystkie pozycje paragonu o unikalnym ID
|
||||
*
|
||||
* @param $id -
|
||||
* unikalny ID paragonu
|
||||
*/
|
||||
public static function getByReceiptId($id) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$query = "SELECT * FROM ecmreceiptitems WHERE ecmreceipt_id='$id'";
|
||||
$result = $db->query ( $query );
|
||||
|
||||
return ReceiptItems::getAllFromResult ( $result );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca w formie tablicy wszystkie wiersze odpowiedzi na zapytanie
|
||||
*
|
||||
* @param
|
||||
* $result
|
||||
* @return Zwraca wiersze w postacie tablicy
|
||||
*/
|
||||
public static function getAllFromResult($result) {
|
||||
$itemsArray = array ();
|
||||
while ( $row = $result->fetch_assoc () ) {
|
||||
array_push ( $itemsArray, $row );
|
||||
}
|
||||
return $itemsArray;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user