Add php files
This commit is contained in:
73
modules/EcmReports/class/class.Account.php
Normal file
73
modules/EcmReports/class/class.Account.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
183
modules/EcmReports/class/class.PurchaseInvoice.php
Normal file
183
modules/EcmReports/class/class.PurchaseInvoice.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
include ("class.PurchaseInvoiceItems.php");
|
||||
|
||||
/**
|
||||
* Klasa reprezentujпїЅca fakturпїЅ
|
||||
*
|
||||
* @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пїЅ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/EcmReports/class/class.PurchaseInvoiceH.php
Normal file
36
modules/EcmReports/class/class.PurchaseInvoiceH.php
Normal 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пїЅ 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 );
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
41
modules/EcmReports/class/class.PurchaseInvoiceItems.php
Normal file
41
modules/EcmReports/class/class.PurchaseInvoiceItems.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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пїЅ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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user