<?php
define('DB_USER', 'trusrpca_admin');
define('DB_PASS', 'trustotech@2020');
define('DB_NAME', 'trusrpca_apple_clinic_system_new');
define('DB_HOST', 'localhost');
define('trusto_VERSION', '');
define('DB_website_NAME', 'trusrpca_apple_clinic');


//
/*
System Note:
%%%%%%%%%Note%%%%%Note%%%%%%Note%%%%%%Note%%%%%%%%%Note%%%%%%%Note%%%%%%%Note%%%%%%Note%%%%%Note%%%%%%%%Note%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if the user type is api
	- after creating a user we must add a user to the web API 
if the user type is a distribution
	- after creating a user in the user account we must fill their prefix 
	- in the database we have app_unique_id filed we must fill it same data when sending a request to the distribution API in filed name 'unique_id'
%%%%%%%%%Note%%%%%Note%%%%%%Note%%%%%%Note%%%%%%%%%Note%%%%%%%Note%%%%%%%Note%%%%%%Note%%%%%Note%%%%%%%%Note%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Version notes: trusto_4.2
***** 3.1 *****
- add in head description,keywords,author
- add action(copy,edit) to UserAccAccounts in Accounting
***** 3.2 *****
- add in Ticketing modal - Maintenance
    -  Maintenance Type List
    -  Maintenance Supporter
    -  Maintenance List
- DB add new permeation and tables
***** 3.3 *****
- Modify Pos
    - Product Name and Price with Permission(Permission don't work with admin)
- Modify table Service in main_pos
- Modify Shortcut icon
- Delete manifest family
***** 3.4 *****
- add a new customer product page and set it in the link top header
- add invoice print to phone 
- add maintenance for phone store in Ticketing
- edit Maintenance for production 
    - add a print for the production process 
    - add states for production process when finish will change product
    - add production barcode with print and set it from the production process
    - add page PayrollForEmployeeProcess cost emp in hrm->Payroll
- edit pos refresh
***** 3.5 *****
- add a new page for add/view user shift 
     - view
     - delete
     - edit
***** 3.6 *****
- add new pages for multi DB to merge more than 1 database in the same system 
     - Inventory/multi_invoice for sales invoice and we can view it or print it and it is for parent system
     - Inventory/multi_order_invoice for a purchase order from another database and in the parent system they see it as a purchase invoice
        - you can view it and print 
        - you can change it to a sales invoice 
        - you can change their status to in progress or approve it (who have this order can see their status in their system on page Inventory/multi_order_invoice_state)
     - Inventory/multi_order_invoice_state to see the state of purchase invoice in child system 
***** 4.0 *****
- modify permeation activate_second_currency when turn off will hide all  second_currency(acc - stock - Inentry/report)
- add permeation products_without_vat
***** 4.2 *****
- add messages model with there permeation and modify database have 1 table messages
- add shift user time add-edit-delete-view and update current database
- add upload suppliers
***** 5.0 *****
- add upload  logo for system ACC -> Organization Setting -> Upload Image
- change lang file in system
***** 5.1 *****
delete sales man from sales invoice select  by default.
show sec currency in all invoice.
pos- function order - button red color check it.
return -> actual return in inventory.
بالاشعارات product customer cancel
ارقام حد كل شي فيه list
***** 5.2.1 *****
modify Inventory 
***** 5.2.2 *****
start modify Accounting 
***** 5.2.3 *****
start modify HRM 
***** 5.2.4 *****
start modify POS 
***** 5.2.5 *****
start modify Stock 
- add setting permission disable_merge_same_prod_return
- add new scale jhma (not checked it yet)
***** 5.2.6 *****
start modify Garage 
- add sync folder
***** 5.2.7 *****
start modify Maintenance/Production 
- add proccess color table 
***** 5.2.8 *****
start modify CRM 
***** 5.2.9 *****
start modify Ticketing 
***** 5.2.10 *****
start modify Settings 
- modify DB
***** 5.3 *****
########## FINISH SYSTEM MODIFY ##########
***** 5.3.1 *****
add animation on public static function draw_menu_blocks
libs\GeneralFunctions\Forms.php
***** 5.3.2 *****
- add QR Code to pos
- delete dublicate end-of-day on system setting
***** 5.3.3 *****
- fix after final test
***** 5.3.4 *****
- add alert expiry product with setting Permission on database to more control like:
    -product_expiry_alert_days
    -enable_expiry_alert
    -count_expiry_product_alert (how many times show alert)
***** 5.3.5 *****
- add pos shortcut F1 cash - F2 print last invoice we can use more
***** 5.3.6 *****
- get optical system
***** 5.3.7 *****
- fix uom convirsion on sales invoice
- fix pos uom conversion 
***** 5.3.8 *****
- merage distribution with new system
- add update template
- add empty system
- modify pos and there values 
- database update
***** 5.3.9 *****
- after change color style for all system 
***** 5.4.0 *****
- edit color in Dashboard 
***** 5.4.1 *****
- add qrcode image to sumatra in function [function posInvPOS ] from file [libs\Inventory\Invoicepos.php]
- add copy of [service] for pos in Inventry => Inventry Setting
- Delete role Permission 
***** 5.4.2 *****
- finish edit 15 modification HRM
    - add daily for payroll and delete action on TotalPayslipDetails
***** 5.4.3 *****
- finish edit 17 modification HRM
    - add weekly for commission
***** 5.4.4 *****
- finish edit 21 modification signature
    - add to tbl_common_permission -> signature
    - sales_inv_fields_hide in setting
***** 5.4.5 *****
- finish edit 19 modification pos floors
    - add to tbl_default_settings -> enable_user_floors
    - add to tbl_common_permission -> all_floors 
***** 5.4.6 *****
- start - add total product with and without vat to sales invoice
***** 5.4.7 *****
- add permission to depo model for add branch
- delete product customer from db - system
- delete desripution from add user
- delete PayrollForEmployeeProcess
- change system expiry page
- add system note
***** 5.4.8 *****
- add vat to pos
- add vat percent to pos template
- add {show_all_subscriptions} permeation to subscription_fees_list.php 
- fix product service
***** 5.4.9 *****
- add an option for users to Show their customers and their invoices in all invoices in the Inventory
- Full Edit for DB file
- edit pos Generate and pos cash to set cash amount
***** 5.5.0 *****
- add kitchen order to view all takeaway order
- Merge same items in 1 row on POS
    - Setting name is merge_same_item_in_1_row
    - modify file in script.js function AddItemToTable
    - modify main_pos.php just add input for setting to set it in script.js file
- POS: we hide count person it is not do anything
- POS: Function -> order we solve it now can get customer by QR scanner, barcode scanner or customer search
- Add QR code for return invoice
- Add View return invoice in pos -> function -> return list
- Add copy qr code for pos distribution 
- modify pos search item and the user can now search by barcode
- delete PHP function strtotime from our function get_remain_expiry_date because any year after 2030 will have a problem (search for it)
- modify message system style
***** 5.5.1 *****
- add condition  to function get_total_subscription_fees for Subscriptions (13/7/2022)
- add date paid filter subscription fees list and set data_time to be for paid date-time
- add unique_customer_phone_number in system setting
- add unique_supplier_phone_number in system setting
- fix account payment in add invoice
***** 5.5.2 *****
- fix input pos price and add system setting ('does_not_allow_to_decrease_pos_item_price') 
- fix DepotContent total cost
- fix customer import with salesman and user
- fix customer branch at add sales invoice
***** 5.5.3 *****
- add barcode prefix and description in category
- generate barcode in add product when choosing a category
- add system setting ('enable_category_barcode') 
***** 5.5.4 *****
- update optical fields ✅
- update archive_list style ✅
- fix qr code update date to date created ✅
- invoice-profit from invoice list option invoice => fix return option ✅
- category sort order input delete required and update database ✅
- sales invoice add class for all payment method❓
    * credit_card_class ❓
    * cheque_class ❓
    * cash_class ❓
    * others_class ❓
- add barcode code libs\Inventory\Product.php  function printBarCode linr => $this->info['barcode_code'] = $this->info['Code']; ❓
- add edit bank ✅
- Fix Go Delivery from sales order error (This Order is totally delivered. ) ✅
    @ error come from database query when try to get remaining_qty and fix it  ✅
    ! function name libs\Inventory\DeliveryNote.php => get_order_for_delivery_note -> $query_details ✅
- Fix 2 error Accounting ✅
    @ data not display in table error from page Views\Accounting\ledgerMultiAccounts.php  and function Controllers\ACCAjax.php => function ledgerAjax ✅
    ! this function use it from 2 page Views\Accounting\ledger.php and Views\Accounting\ledgerMultiAccounts.php so we add in ajax from_multi_accounts in page ledgerMultiAccounts to check from where get data and add if else condition on function ledgerAjax to solve it ✅
    @ undefinde error on page Views\Accounting\ledgerMultiAccounts.php ✅
    ! error from javascript part ✅
- add barcode to page Views\Inventory\TotalItemsPerDate.php and add product_plu to sql ✅
- add to tbl_default_settings => enable_auto_increment_invoice_sync if sync is enable and send invoice from branch to server invoice number will continue in server ✅
-*add system setting 'round_digits' and apply it for all system to manage decimal number after digit ✅
- add customer & supplier vat + cr to sales and purchase invoice , order , return (27-12-2022) ✅
- Change city option in update organization and edit button => Views\Accounting\EditOrganization.php (27-12-2022)  ✅
- totals_all_invoice_type user Permission to show/hide for page Views\Dashboard.php => Total Invoice By Type (27-12-2022) ✅
- add archive_title , archive_details to Views\general\archive_list.php and update DB (27-12-2022) ✅
- add header to page Views\Accounting\ledgerMultiAccounts.php (28-12-2022) ✅
- fix dashboard box Daily Purchase , Daily Sales etc ... (28-12-2022) ✅
- add autofill item/product into sales invoice and return (29-12-2022) ✅
    # enable in system setting 'enable_autofill_product_in_invoice' ✅
    # fill barcode for item we use it by default in system setting 'product_barcode_for_autofill_in_invoice' ✅
    # enable in system setting 'disable_merge_same_prod_return' for return ✅
- login to other company from login page and hide it from header (29-12-2022) ✅
- change input for add payment to textarea (30-12-2022) ✅
- add a new page for product barcode scan without login and we can access to this page by  (30-12-2022) ✅
    # enable system setting 'enable_product_barcode_page' ✅
    # open it from login page ✅
    # file path 'Views\product_page.php' ✅
- in add payment page when get invoice and fill all pricese we add total invoice for first row in payment (30-12-2022) ✅
- update smart diner floor and table (02-01-2023)
    # we can add multi user for floor and table
***** 5.5.5 *****
- add sync backup folder to sync local database to online by FTP  (06-01-2023)
- add category name to sales invoice item 'Cat_Name' (09-01-2023)
- fix error when search on col into datatable we update code libs\Common\DataTable.php => complex function (09-01-2023)
- add new tags to sales invoice and quotaion
***** 5.5.6 *****
- when disbale an item will add adjust item to make item equal to 0 update function libs\Common\SettingClass.php => function enableDisableItem (16-1-2023)
########################SQL######################SQL########################SQL#########################
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'enable_when_disable_item_qty_zero', '1', 'bool', '1') (19-1-2023)
########################SQL######################SQL########################SQL#########################
SQL for optical table update database
########################SQL######################SQL########################SQL#########################
ALTER TABLE
    `tbl_invoices` ADD `cl_r_sph` VARCHAR(25) NULL ,
    ADD `cl_r_cyl` VARCHAR(25) NULL ,
    ADD `cl_r_axis` VARCHAR(25) NULL ,
    ADD `cl_r_ipd` VARCHAR(25) NULL ,
    ADD `cl_l_sph` VARCHAR(25) NULL ,
    ADD `cl_l_cyl` VARCHAR(25) NULL ,
    ADD `cl_l_axis` VARCHAR(25) NULL,
    ADD `cl_l_ipd` VARCHAR(25) NULL;
########################SQL######################SQL########################SQL#########################
view invoice_list_main
    `i`.`cl_r_sph` AS `cl_r_sph`,
    `i`.`cl_r_cyl` AS `cl_r_cyl`,
    `i`.`cl_r_axis` AS `cl_r_axis`,
    `i`.`cl_r_ipd` AS `cl_r_ipd`,
    `i`.`cl_l_sph` AS `cl_l_sph`,
    `i`.`cl_l_cyl` AS `cl_l_cyl`,
    `i`.`cl_l_axis` AS `cl_l_axis`,
    `i`.`cl_l_ipd` AS `cl_l_ipd`,
########################SQL######################SQL########################SQL#########################

- fix bugs in station tap and we fix station purchase , sales templates and station sales list

***** 5.5.7 Item rate % *****
SQL for rate
########################SQL######################SQL#######################SQL#########################
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'product_rate', '0', 'pos_number', '0');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'product_rate', 'Product Rate', '1341');
ALTER TABLE `tbl_stock_products` ADD `is_rate` TINYINT(4) NOT NULL DEFAULT '0' ;
########################SQL######################SQL########################SQL#########################
-item modify rate for lebanon to change all items prices
*******************************************************
***** 5.5.8 Branches *****
*******************************************************
########################SQL######################SQL#######################SQL#########################
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'Branches', 'Branches', '0');✅✅
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'Depots', 'Depots', '2072');✅✅
ALTER TABLE `tbl_customers` ADD `branch_id` INT NULL ;✅✅
ALTER TABLE `tbl_stock_suppliers` ADD `branch_id` INT NULL ;✅✅
ALTER TABLE `tbl_pos_customers` ADD `branch_id` INT NULL ;✅✅


View datasource_productlist:✅✅
    `p`.`branch_id` AS `branch_id`,✅✅

view customer_list:✅✅
    `c`.`branch_id` AS `branch_id`,✅✅

view supplier_list✅✅
    `s`.`branch_id` AS `branch_id`,✅✅

view customer_limit_balance✅✅
    `c`.`branch_id` AS `branch_id`,✅✅

view product_mov_purchase✅✅
    `d`.`Item_ID` AS `Entery_ID`,✅✅

view product_mov_purchase✅✅
    `i`.`branch_id` AS `branch_id`,✅✅

view payment_list✅✅
    `p`.`branch_id` AS `branch_id`,✅✅

view credit_list✅✅
    `n`.`branch_id` AS `branch_id`,✅✅

view debit_list✅✅
    `n`.`branch_id` AS `branch_id`,✅✅

get full view customer_supplier_contacts from local DB✅✅


add new system setting for lebanon vat if we want to exchange from $ to L.L
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'lebanon_vat_amount', '15000', 'pos_number', '0');

########################SQL######################SQL#######################SQL#########################
- fix return amount for pos
- fix in lebanon in top supplier and top customer 
- fix supply date in edit sales invoice

*******************************************************
***** 5.5.9 Branches templates *****
*******************************************************
########################SQL######################SQL#######################SQL#########################
//delete employee from chart of account
  delete from `tbl_chart_of_accounts` WHERE Account_Code BETWEEN 42100001 and 42100032;
  delete from `tbl_chart_of_accounts` WHERE Account_Code BETWEEN 63110001 and 63110032;
// add filed is_actual for tbl_common_users  to user
ALTER TABLE `tbl_common_users` ADD `is_actual` INT NOT NULL DEFAULT '0';
--------
drop view view_users
then add with `u`.`is_actual` AS `is_actual_user`
########################SQL######################SQL#######################SQL#########################
✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅
✅✅✅✅✅✅ all sql add to database trusto_lebanon.5.5.8 & trusto_saudi.5.5.8 ✅✅✅✅✅✅✅✅✅✅✅✅
✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅
########################SQL######################SQL#######################SQL#########################
update tbl_common_users set secret_code = NULL;
update tbl_common_users set user_session_path = NULL;
ALTER TABLE `tbl_print_template` ADD `branch_id` INT NULL;
update `tbl_print_template` set `branch_id` = 1;

INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'template_branches_list', 'View Template list', '422');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'template_branches', 'Add Template', '2074');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'edit_template', 'Edit Template', '2074');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'delete_template', 'Delete Template', '2074');
delete FROM `tbl_devices` ;
CREATE TABLE `tbl_template_attribute` ( `attribute_id` INT NOT NULL AUTO_INCREMENT , `attribute_key` TEXT NULL , `attribute_value` TEXT NULL , PRIMARY KEY (`attribute_id`)) ENGINE = InnoDB;
ALTER TABLE `tbl_template_attribute` ADD `template_id` INT NULL;
UPDATE `tbl_print_template` set template_name = CONCAT('Server ',template_key);

INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'attribute_list', 'View Template Attribute list', '422');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'add_attribute', 'Add Template Attribute', '2078');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'delete_template_attribute', 'Delete Template Attribute', '2078');
ALTER TABLE `tbl_template_attribute`  ADD `attribute_type` INT NULL COMMENT '1 for text - 2 for image - 3 for formula';
ALTER TABLE `tbl_template_attribute` ADD `branch_id` INT NULL DEFAULT '0';

########################SQL######################SQL#######################SQL#########################
📝 ✅ note add permation Branches and depots [delete_template edit_template template_branches_list template_branches] and all above permation to admin 

📝 ✅ note delete all images from org_logo 

- ✅ update category add multi category in same page
*******************************************************
***** 5.6.0 Customer Customize *****
*******************************************************
########################SQL######################SQL#######################SQL#########################
ALTER TABLE `tbl_inventory_purchases` ADD `driver_id` INT NULL DEFAULT '0' ;
ALTER TABLE `tbl_invoices` ADD `from_place` TEXT NULL  , ADD `to_place` TEXT NULL  ;
ALTER TABLE `tbl_inventory_purchases` ADD `from_place` TEXT NULL  , ADD `to_place` TEXT NULL  ;
ALTER TABLE `tbl_purchase_order` ADD `driver_id` INT NULL DEFAULT '0' , ADD `from_place` TEXT NULL  , ADD `to_place` TEXT NULL  ;

UPDATE `tbl_default_settings` SET `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Commission\",\"8\":\"Vehicle\",\"9\":\"Employee\",\"10\":\"Depot\",\"11\":\"Item Note\",\"12\":\"Profit Margin\",\"13\":\"Lot Number\",\"14\":\"Serial Number\",\"15\":\"Contra\",\"16\":\"Customer Code\",\"17\":\"Order\",\"18\":\"Second VAT %\",\"19\":\"Second VAT Amount\",\"20\":\"Custome Name Alias\",\"21\":\"Customer Address Alias\",\"22\":\"pos customer\",\"23\":\"Local Rate\",\"24\":\"Second Currency Rate\",\"25\":\"Shipping Note\",\"26\":\"Shipping Account\",\"27\":\"Shipping Company\",\"28\":\"Shipping Amount\",\"29\":\"Job\",\"30\":\"Project\",\"31\":\"Due Date\",\"32\":\"Truck\",\"33\":\"brand_name\",\"34\":\"po\",\"35\":\"project_name_inv\",\"36\":\"project_code\",\"37\":\"job_inv\",\"38\":\"our_ref\",\"39\":\"supply_date\",\"40\":\"additional cost\",\"41\":\"total\",\"42\":\"optical table\",\"43\":\"signature\",\"44\":\"from place\",\"45\":\"to place\",\"46\":\"driver name\"}' WHERE `tbl_default_settings`.`setting_id` = 110;
UPDATE `tbl_default_settings` SET `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Item Note\",\"8\":\"Lot Number\",\"9\":\"Serial Number\",\"10\":\"Pricing Class\",\"11\":\"Depot\",\"12\":\"Supplier Code\",\"13\":\"Order\",\"14\":\"Second VAT\",\"15\":\"Second VAT Amount\",\"16\":\"Delivery Date\",\"17\":\"Job\",\"18\":\"Local Rate\",\"19\":\"Second Currency Rate\",\"20\":\"Due Date\",\"21\":\"Item Extra Cost\",\"22\":\"brand_name\",\"23\":\"additional cost\",\"24\":\"total\",\"25\":\"from place\",\"26\":\"to place\",\"27\":\"driver name\"}' WHERE `tbl_default_settings`.`setting_id` = 111;
UPDATE `tbl_default_settings` SET `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Commission\",\"8\":\"Vehicle\",\"9\":\"Employee\",\"10\":\"Depot\",\"11\":\"Item Note\",\"12\":\"Profit Margin\",\"13\":\"Lot Number\",\"14\":\"Serial Number\",\"15\":\"Supplier Class\",\"16\":\"Cost\",\"17\":\"Other Cost\",\"18\":\"Customer Code\",\"19\":\"po\",\"20\":\"Project Name\",\"21\":\"Project Code\",\"22\":\"job\",\"23\":\"Our Ref\",\"24\":\"Supply Date\",\"25\":\"customer name alias\",\"26\":\"customer address alias\",\"27\":\"from place\",\"28\":\"to place\",\"29\":\"driver name\"}' WHERE `tbl_default_settings`.`setting_id` = 132;
UPDATE `tbl_default_settings` SET `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Item Note\",\"8\":\"Lot Number\",\"9\":\"Serial Number\",\"10\":\"Pricing Class\",\"11\":\"Supplier Code\",\"12\":\"Delivery Date\",\"13\":\"Due Date\",\"14\":\"Job\",\"15\":\"Project\",\"16\":\"Local Rate\",\"17\":\"from place\",\"18\":\"to place\",\"19\":\"driver name\"}' WHERE `tbl_default_settings`.`setting_id` = 133;

view purchase_main_list
    `i`.`driver_id` AS `driver_id`,
    `i`.`from_place` AS `from_place`,
    `i`.`to_place` AS `to_place`,
view invoice_list_main
    `i`.`driver_id` AS `driver_id`,
    `i`.`from_place` AS `from_place`,
    `i`.`to_place` AS `to_place`,
view purchase_order_list
    `p`.`driver_id` AS `driver_id`,
    `p`.`from_place` AS `from_place`,
    `p`.`to_place` AS `to_place`,

########################SQL######################SQL#######################SQL#########################

- add fileds for invoice , Quotation , order (sales and purchese )
*******************************************************
***** 5.6.1 POS *****
*******************************************************
SQL for drivers
########################SQL######################SQL#######################SQL#########################
add from timr to time and date for order and next sales invoice when update system must hide must of them
ALTER TABLE `tbl_purchase_order_details` ADD `from_time` TEXT NULL , ADD `to_time` TEXT NULL , ADD `modify_date` TEXT NULL ;
ALTER TABLE `tbl_purchase_order_details` ADD `driver_id` INT NULL  ;

ALTER TABLE `tbl_invoice_products_details` ADD `from_time` TEXT NULL , ADD `to_time` TEXT NULL , ADD `modify_date` TEXT NULL ;
ALTER TABLE `tbl_invoice_products_details` ADD `driver_id` INT NULL  ;
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'enable_second_cash', '0', 'bool', '1');

UPDATE `tbl_default_settings` SET `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Commission\",\"8\":\"Vehicle\",\"9\":\"Employee\",\"10\":\"Depot\",\"11\":\"Item Note\",\"12\":\"Profit Margin\",\"13\":\"Lot Number\",\"14\":\"Serial Number\",\"15\":\"Supplier Class\",\"16\":\"Cost\",\"17\":\"Other Cost\",\"18\":\"Customer Code\",\"19\":\"po\",\"20\":\"Project Name\",\"21\":\"Project Code\",\"22\":\"job\",\"23\":\"Our Ref\",\"24\":\"Supply Date\",\"25\":\"customer name alias\",\"26\":\"customer address alias\",\"27\":\"from place\",\"28\":\"to place\",\"29\":\"driver name\",\"30\":\"item driver name\" ,\"31\":\"from time item\",\"32\":\"to time item\",\"33\":\"modify date item\"}' WHERE `tbl_default_settings`.`setting_id` = 132;
UPDATE `tbl_default_settings` SET `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Commission\",\"8\":\"Vehicle\",\"9\":\"Employee\",\"10\":\"Depot\",\"11\":\"Item Note\",\"12\":\"Profit Margin\",\"13\":\"Lot Number\",\"14\":\"Serial Number\",\"15\":\"Contra\",\"16\":\"Customer Code\",\"17\":\"Order\",\"18\":\"Second VAT %\",\"19\":\"Second VAT Amount\",\"20\":\"Custome Name Alias\",\"21\":\"Customer Address Alias\",\"22\":\"pos customer\",\"23\":\"Local Rate\",\"24\":\"Second Currency Rate\",\"25\":\"Shipping Note\",\"26\":\"Shipping Account\",\"27\":\"Shipping Company\",\"28\":\"Shipping Amount\",\"29\":\"Job\",\"30\":\"Project\",\"31\":\"Due Date\",\"32\":\"Truck\",\"33\":\"brand_name\",\"34\":\"po\",\"35\":\"project_name_inv\",\"36\":\"project_code\",\"37\":\"job_inv\",\"38\":\"our_ref\",\"39\":\"supply_date\",\"40\":\"additional cost\",\"41\":\"total\",\"42\":\"optical table\",\"43\":\"signature\",\"44\":\"from place\",\"45\":\"to place\",\"46\":\"driver name\",\"47\":\" item driver name\",\"48\":\"item from time\",\"49\":\"item to time\",\"50\":\"modify date\"}' WHERE `tbl_default_settings`.`setting_id` = 110;
########################SQL######################SQL#######################SQL#########################

########################SQL######################SQL#######################SQL#########################
ALTER TABLE `tbl_invoices` ADD `second_cash_Invoice_Currency` INT NULL AFTER `to_place`, ADD `second_cash_currency_rate` DOUBLE NULL AFTER `second_cash_Invoice_Currency`, ADD `second_cash_Invoice_Paid_Amount` DOUBLE NULL AFTER `second_cash_currency_rate`;
ALTER TABLE `tbl_invoices` ADD `first_cash_Invoice_Paid_Amount` DOUBLE NULL ;
INSERT INTO `tbl_account_setting` (`id`, `acc_setting_name`, `acc_setting_value`, `main_type`, `sub_type`, `setting_type`) VALUES (NULL, 'second_curr_cash_account', '', 'pay', 'cash', 'table##s##chart_of_accounts')

view invoice_list_main
    `i`.`first_cash_Invoice_Paid_Amount` AS `first_cash_Invoice_Paid_Amount`,
    `i`.`second_cash_Invoice_Paid_Amount` AS `second_cash_Invoice_Paid_Amount`,
    `i`.`second_cash_currency_rate` AS `second_cash_currency_rate`,
    `i`.`second_cash_Invoice_Currency` AS `second_cash_Invoice_Currency`,

########################SQL######################SQL#######################SQL#########################
- add for account setting second_curr_cash_account for second cash
- for $ and L.L same time change here libs\Inventory\Product.php => function get_product_price => and pc.Product_Price > 0
- add new systeom setting for second cash for second currency and name it enable_second_cash

- add for POS to table tbl_invoices attributes  second_cash_Invoice_Currency , second_cash_currency_rate , second_cash_Invoice_Paid_Amount
-* set cash for user same as local currency in system setting
########################SQL######################SQL#######################SQL#########################
delete FROM `tbl_brand_products`;
########################SQL######################SQL#######################SQL#########################
*******************************************************
***** 5.6.2 POS/Phone *****
*******************************************************

########################SQL######################SQL#######################SQL#########################

INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES
(null, 'view_all_maintenance', 'View All Maintenance', 2015),
(null, 'maintenance_sales_invoice_edit', 'Maintenance Sales Invoice Edit', 2015),
(null, 'maintenance_sales_invoice', 'Maintenance Sales Invoice', 2015),
(null, 'enable_maintenance_controller', 'Enable All Maintenance Controller', 2015);
INSERT INTO `tbl_ticketing_status` (`ticketing_status_id`, `ticketing_status_name`) VALUES (NULL, 'Taken');

ALTER TABLE `tbl_maintenance` ADD `Employee_ID` INT NULL ,ADD `nonce` TEXT NULL , ADD `maintenance_note` TEXT NULL ;
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES
(null, 'maintenance_sales_invoice_fields_to_hide', '3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,32,34,35,36,37,38,40,41', 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Commission\",\"8\":\"Vehicle\",\"9\":\"Employee\",\"10\":\"Depot\",\"11\":\"Item Note\",\"12\":\"Profit Margin\",\"13\":\"Lot Number\",\"14\":\"Serial Number\",\"15\":\"Contra\",\"16\":\"Customer Code\",\"17\":\"Order\",\"18\":\"Second VAT %\",\"19\":\"Second VAT Amount\",\"20\":\"Custome Name Alias\",\"21\":\"Customer Address Alias\",\"22\":\"pos customer\",\"23\":\"Local Rate\",\"24\":\"Second Currency Rate\",\"25\":\"Shipping Note\",\"26\":\"Shipping Account\",\"27\":\"Shipping Company\",\"28\":\"Shipping Amount\",\"29\":\"Job\",\"30\":\"Project\",\"31\":\"Due Date\",\"32\":\"Truck\",\"33\":\"brand_name\",\"34\":\"ttc price\",\"35\":\"additional cost\",\"36\":\"total\",\"37\":\"expiry\",\"38\":\"expiry\",\"39\":\"extra_icon\",\"40\":\"hide bottom\",\"41\":\"hide button\"}', 1);

ALTER TABLE `tbl_invoices` ADD `invoice_void_total` DOUBLE NULL ;

INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'rate_type_one', '0', 'pos_number', '0');
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'rate_type_two', '0', 'pos_number', '0');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'rate_type_one', 'Rate Type One', '1341');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'rate_type_two', 'Rate Type Two', '1341');
ALTER TABLE `tbl_stock_products` ADD `is_rate_type_one` DOUBLE NULL  , ADD `is_rate_type_two` DOUBLE NULL  ;
INSERT INTO `tbl_landings` (`landing_id`, `landing_name`, `landing_url`) VALUES (NULL, 'Ticketing', 'Ticketing');
INSERT INTO `tbl_common_currency` (`Currency_ID`, `Currency_Name`, `Currency_Code`, `Currency_Symbol`, `currency_round`) VALUES (NULL, 'Lebanese Pound Sayrafa', 'LBS', 'L.L.', '250');



view invoice_list_main
    `i`.`order_id` AS `sales_order_id`,
view detailed_purchase_report
    `d`.`lot_nb` AS `lot_nb`,
    `d`.`serial_nb` AS `serial_nb`,

view maintenance_list
    `maintenance`.`maintenance_note` AS `maintenance_note`,


get view maintenance_list from phone
########################SQL######################SQL#######################SQL#########################

-    give admin all new permation and test it in user account
-    delete data Adjust Product Quantity List and  Assign Product Quantity List from 2021
-    set table to 0 in pos
-    ADD NEW currency صيرفة add exchange for it
- princing list Controllers\InventoryAjax.php -> function PricingListRequest change formatNumber to public_round_number
- system setting number_format_precision set it to 2,number_format_remove_zeros it's true
- fix Views\Stock\multi_product_location.php edit line 203 from if (v1.responseJSON == 'OK') to if (v1.responseJSON[1] == 'OK') 

- add comments for filter branch 
    {
        comment="value='<?php echo smc_session()['user_accounts']['branch_id'] ?>' data-select-name='<?php echo smc_session()['user_accounts']['branch_name']; ?>'"
        comment="value='<?php echo smc_session()['user_accounts']['depot_id'] ?>' data-select-name='<?php echo smc_session()['user_accounts']['Depot_Name']; ?>'"
    }


########################SQL######################SQL#######################SQL#########################
ALTER TABLE `tbl_inventory_purchase_items` ADD `driver_id` INT NULL  ;

ALTER TABLE `tbl_inventory_purchase_items` ADD `vehicle_id` INT NULL  ;
ALTER TABLE `tbl_inventory_purchase_items` ADD `modify_date` TEXT NULL  ;
UPDATE `tbl_default_settings` SET `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Item Note\",\"8\":\"Lot Number\",\"9\":\"Serial Number\",\"10\":\"Pricing Class\",\"11\":\"Depot\",\"12\":\"Supplier Code\",\"13\":\"Order\",\"14\":\"Second VAT\",\"15\":\"Second VAT Amount\",\"16\":\"Delivery Date\",\"17\":\"Job\",\"18\":\"Local Rate\",\"19\":\"Second Currency Rate\",\"20\":\"Due Date\",\"21\":\"Item Extra Cost\",\"22\":\"brand_name\",\"23\":\"additional cost\",\"24\":\"total\",\"25\":\"from place\",\"26\":\"to place\",\"27\":\"driver name\",\"28\":\"modify date item\",\"29\":\"vehicle item\",\"30\":\"driver name item\"}' WHERE `tbl_default_settings`.`setting_id` = 111;

########################SQL######################SQL#######################SQL#########################
*******************************************************
***** 5.6.3 Kublan *****
*******************************************************
########################SQL######################SQL#######################SQL#########################
delete from tbl_invoice_payments;

ALTER TABLE `tbl_stock_products` ADD `n_width` FLOAT NULL  , ADD `n_height` FLOAT NULL  ;
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'enable_Kabalan_height_width', '0', 'bool', '1');
ALTER TABLE `tbl_invoice_products_details` ADD `n_height` FLOAT NOT NULL DEFAULT '0'  , ADD `n_width` FLOAT NOT NULL DEFAULT '0'  , ADD `n_total` FLOAT NOT NULL DEFAULT '0'  ;
ALTER TABLE `tbl_inventory_purchase_items` ADD `n_height` FLOAT NOT NULL DEFAULT '0'  , ADD `n_width` FLOAT NOT NULL DEFAULT '0'  , ADD `n_total` FLOAT NOT NULL DEFAULT '0'  ;
ALTER TABLE `tbl_purchase_order_details` ADD `n_height` FLOAT NOT NULL DEFAULT '0'  , ADD `n_width` FLOAT NOT NULL DEFAULT '0'  , ADD `n_total` FLOAT NOT NULL DEFAULT '0'  ;


INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'lebanon_vat_amount', 'Lebanon vat amount', '25');

-- start for Ali romani 
ALTER TABLE `tbl_stock_products` ADD `effect_qty_link_product` INT NOT NULL DEFAULT '0'  ;
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'effect_qty_link_product', 'effect qty link product from sales invoice', '25');
ALTER TABLE `tbl_invoice_products_details` ADD `qty_link` FLOAT NOT NULL DEFAULT '0'  ;

-- view product_mov_invoice
--    `d`.`modify_date` AS `modify_date`,
--     `d`.`qty_link` AS `qty_link`,
-- view product_movement_invoice
--    `d`.`qty_link` AS `qty_link`,

-- end for Ali romani 

########################SQL######################SQL#######################SQL#########################
- new system setting Kabalan height width (enable_Kabalan_height_width) for height width in system
- old system setting Kabalan enable_category_barcode
- change amount of lebanon_vat_amount from inventory -> products 
*** add for admin and superuser lebanon_vat_amount permation 
- add to view_deposit_withdrawal [function getDWByID] new elements {to_WithDrawal_Amount_word_ar , to_WithDrawal_Amount_word_en, from_WithDrawal_Amount_word_ar ,from_WithDrawal_Amount_word_en}
- add to function getExpenseToPrint new elements { total_price_word_ar total_price_word_en total_price_with_vat_word_ar total_price_with_vat_word_en}
- fix return error ReturnNoInvoice.php in function EnableAutoComplete with last price the error is when  try to get last price we need customer id to get there customer class price 
- fix Dashboard Suppliers Credit with function viewCustomersSuppliersBalance 
*** end of day system setting no sumitra
*** delete all brand
*** delete tbl_damage_details
- pos can search for all item if enable setting show_products_from_all_branches  
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&& start with customers certificate and customers contra &&&
########################SQL######################SQL#######################SQL#########################
CREATE TABLE `tbl_customers_certificate` ( `id` INT NOT NULL AUTO_INCREMENT , `customer_id` INT NULL , `certificate_info` TEXT NULL , `start_date` VARCHAR(30) NULL , `end_date` VARCHAR(30) NULL , `crate_data_time` VARCHAR(60) NULL , `login_user` INT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE VIEW `customerscertificateview` AS select `c`.`id` AS `id`, `c`.`customer_id` AS `customer_id`, `c`.`certificate_info` AS `certificate_info`, `c`.`start_date` AS `start_date`, `c`.`end_date` AS `end_date`, `c`.`crate_data_time` AS `crate_data_time`, `c`.`login_user` AS `login_user`, `cu`.`Customer_Name` AS `Customer_Name` from ( `tbl_customers_certificate` `c` left join `tbl_customers` `cu` on( ( `cu`.`Customer_ID` = `c`.`customer_id` ) ) ) ; 
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'customers_certificate', 'customers certificate', '41'), (NULL, 'customers_contra', 'customers contra', '41');
CREATE TABLE `tbl_customers_contra`( `id` INT NOT NULL AUTO_INCREMENT, `customer_id` INT NULL, `contra_info` TEXT NULL, `start_date` VARCHAR(30) NULL, `end_date` VARCHAR(30) NULL, `crate_data_time` VARCHAR(60) NULL, `login_user` INT NULL, `product_id` INT NULL, PRIMARY KEY(`id`) ) ENGINE = InnoDB;
ALTER TABLE `tbl_customers_contra` ADD `file_name` TEXT NULL;
CREATE VIEW `customerscontraview` AS SELECT `c`.`id` AS `id`,`c`.`file_name` AS `file_name`, `c`.`customer_id` AS `customer_id`, `c`.`contra_info` AS `contra_info`, `c`.`start_date` AS `start_date`, `c`.`end_date` AS `end_date`, `c`.`crate_data_time` AS `crate_data_time`, `c`.`login_user` AS `login_user`, `c`.`product_id` AS `customer_product_id`, `sp`.`Product_Name` AS `Product_Name`, `cu`.`Customer_Name` AS `Customer_Name` FROM ( `tbl_customers_contra` `c` LEFT JOIN `tbl_customers` `cu` ON ( ( `cu`.`Customer_ID` = `c`.`customer_id` ) ) LEFT JOIN `tbl_stock_products` `sp` ON ( ( `sp`.`Product_ID` = `c`.`product_id` ) ) );

INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'cash_drawer_port', '', 'pos_number', '0');
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'sumatra_print_pos_width', '8.0', 'pos_number', '0');
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'sumatra_print_pos_height', '327.6', 'pos_number', '0');
UPDATE `tbl_default_settings` SET `setting_value` = '0,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22,23,24,25,26,27,29,30,31,32,33,34,35,36,37,38,39,42,43,44,45,46,47,48,49,50,51', `setting_type` = 'option##m##{\"0\":\"Barcode\",\"1\":\"Product name\",\"2\":\"Uom\",\"3\":\"Unit price\",\"4\":\"Discount percent\",\"5\":\"VAT amount\",\"6\":\"VAT percent\",\"7\":\"Commission\",\"8\":\"Vehicle\",\"9\":\"Employee\",\"10\":\"Depot\",\"11\":\"Item Note\",\"12\":\"Profit Margin\",\"13\":\"Lot Number\",\"14\":\"Serial Number\",\"15\":\"Contra\",\"16\":\"Customer Code\",\"17\":\"Order\",\"18\":\"Second VAT %\",\"19\":\"Second VAT Amount\",\"20\":\"Custome Name Alias\",\"21\":\"Customer Address Alias\",\"22\":\"pos customer\",\"23\":\"Local Rate\",\"24\":\"Second Currency Rate\",\"25\":\"Shipping Note\",\"26\":\"Shipping Account\",\"27\":\"Shipping Company\",\"28\":\"Shipping Amount\",\"29\":\"Job\",\"30\":\"Project\",\"31\":\"Due Date\",\"32\":\"Truck\",\"33\":\"brand_name\",\"34\":\"po\",\"35\":\"project_name_inv\",\"36\":\"project_code\",\"37\":\"job_inv\",\"38\":\"our_ref\",\"39\":\"supply_date\",\"40\":\"additional cost\",\"41\":\"total\",\"42\":\"optical table\",\"43\":\"signature\",\"44\":\"from place\",\"45\":\"to place\",\"46\":\"driver name\",\"47\":\" item driver name\",\"48\":\"item from time\",\"49\":\"item to time\",\"50\":\"modify date\",\"51\":\"modify date\"}' WHERE `tbl_default_settings`.`setting_id` = 110

########################SQL######################SQL#######################SQL#########################
- new table in database tbl_customers_certificate
- new permation
    + customers_certificate
    + customers_contra
- new view CustomersCertificateView
- new table in database tbl_customers_contra
- new view CustomersContraView
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

- for cash drawer port to open it without print and must be usb cash_drawer_port for ex: COM5
- add width and height for sumatra print in system setting sumatra_print_pos_height , sumatra_print_pos_width
    !! but if we have a hefty invoice will not print all content !!

*******************************************************
***** 5.6.4 baydoun_corporation *****
*******************************************************
########################SQL######################SQL#######################SQL#########################
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'enable_project_production_process', '0', 'bool', '1');
ALTER TABLE `tbl_purchase_order_details` CHANGE `n_height` `n_height` FLOAT NULL DEFAULT '0', CHANGE `n_width` `n_width` FLOAT NULL DEFAULT '0', CHANGE `n_total` `n_total` FLOAT NULL DEFAULT '0';
UPDATE `tbl_common_permission` SET `Permission_Text` = 'save end of day' WHERE `tbl_common_permission`.`Permission_ID` = 1614;
ALTER TABLE `tbl_table` ADD `is_radius` INT NULL ;

########################SQL######################SQL#######################SQL#########################
ALTER TABLE `tbl_maintenance` ADD `range_cost` VARCHAR(50) NULL AFTER `maintenance_note`;
*******************************************************
***** 5.6.3.1 phone update *****
*******************************************************
* put the new rate of lebanon_vat_amount (system setting) 
- add and edit vat1 (sales invoice) (libs/Inventory/Invoice.php)
- add and edit vat1 (purchase invoice) (libs/Inventory/Purchase.php)
- add and edit vat1 (POS) (libs/Inventory/Invoicepos.php)
- add customer_name and supplier_name on stock_transactions (view/Stock/stock_transactions.php)
- add customer_name and supplier_name in function [stock_transactions_ajax] (Controllers/StockAjax.php)
- edit title of page (edit purchase invoice) (Controllers/Inventory.php) 
- add branch name on customer (view/Inventory/CustomerList.php)
- add 'branch_name' function [CustomerListRequest] (Controllers/InventoryAjax.php)
- add branch_name to database view(customer_list)
- add branch name on supplier (view/Inventory/ViewVendorList.php)
- add branch_name to database view(supplier_list)
- translate branch_name (libs/Common/commonLanguage.php)



*******************************************************
***** 5.6.4.2 *****
*******************************************************
- add select [compare_balance (< > =)] (view/Inventory/CustomerList.php)
- add input choose_balance (view/Inventory/CustomerList.php)
- translate compare_balance and choose_balance (libs/Common/commonLanguage.php)
- add if else condiction to compare_balance function(CustomerListRequest)(view/Inventory/CustomerList.php) 
- active (activate_customer_list_balances(system setting)) 
- hide items where quantity is zero => add $HideQty$ and if condition (view/files/scripts.js)                                                          
- add multi_branch_id to database (tbl_stock_products)
- change from select to multi_select (view/inventory/addproduct.php)
- change from select to multi_select (view/inventory/EditProduct.php) 
- edit in function(addProduct) from branch_id to multi_branch_id (libs/inventory/product.php)
- edit in function(updateProduct) from branch_id to multi_branch_id (libs/inventory/product.php)
- edit in function (listProductRequest)=> multi_branch_id (controllers/inventoryAjax.php) 
- modifying if condition (hasPermission('Branches')) in function (getProductsForCustomer) => (libs/inventory/product.php)
- modifying if condition (hasPermission('Branches')) in function (getProductsForCustomerByClass) => (libs/inventory/product.php)
- modifying if condition (hasPermission('Branches')) in function (getProductsForCustomers) => (libs/inventory/product.php)
- modifying if condition (hasPermission('Branches')) in function (searchBarcodeforPOS) => (libs/inventory/product.php)
- modifying if condition (hasPermission('Branches')) in function (ReturnPriceByClass) => (libs/inventory/product.php)
- modifying if condition (hasPermission('Branches')) in function (costing_report) => (libs/inventory/product.php)
- modifying if condition (hasPermission('Branches')) in function (get_products_to_build) => (libs/inventory/product.php)
(by Aisha)

########################SQL######################SQL#######################SQL#########################
ALTER TABLE `tbl_maintenance` ADD `color_id` INT NULL  , ADD `type_id` INT NULL  , ADD `other_note` TEXT NULL  ;
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'finish_maintenance', 'Finish Maintenance', '2015');

*******************************************************
***** 5.6.4.3 *****
*******************************************************
- add multi_branch_id to POS categories (views/inventory/POSCat.php)
- add multi_branch_id_edit to POS categories (views/inventory/POSCat.php)
- add multi_branch_id on function addCategory (libs/inventory/product.php)
- show selected branches in multi_branch_id_edit[pos categories(edit)](views/inventory/POSCat.php)
- create function getProdCatData to show selected braches(controllers/inventoryAjax.php)
- add checkbox to hide product from POS [id=hide_pos](views/inventory/addproduct)
- add hide_pos in function [addProduct](libs/inventory/product.php)
- add checkbox to hide product from POS [id=hide_pos_to_edit](views/inventory/EditProduct)
- add hide_pos in function [updateProduct](libs/inventory/product.php)
- add hide_pos1 in function [getProduct] to hide product from pos(libs/inventory/product.php)
- add a new permission [hide_pos](views/inventory/addproduct)
(by Aisha)

*******************************************************
***** 5.6.4.4 SQL *****
*******************************************************

########################SQL######################SQL#######################SQL#########################

INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'daily_sales', 'Daily Sales', '44')
########################SQL######################SQL#######################SQL#########################
- update last invoice on pos
- add daily repost for invoice

########################SQL######################SQL#######################
############## 6/12/2023 SQL update ##############
########################SQL######################SQL#######################
ALTER TABLE `tbl_stock_products` ADD `positive_points` INT NULL DEFAULT '0', ADD `negative_points` INT NULL DEFAULT '0';
ALTER VIEW `product_list`  AS  select `products`.`Product_ID` AS `Product_ID`,`products`.`Product_Code` AS `Product_Code`,`products`.`Product_Name` AS `Product_Name`,`products`.`Category_ID` AS `Category_ID`,`products`.`Currency_ID` AS `Currency_ID`,`products`.`Product_Quantity` AS `Product_Quantity`,`products`.`Product_Cost` AS `Product_Cost`,`products`.`Product_Price` AS `Product_Price`,`products`.`Product_Reorder_Point` AS `Product_Reorder_Point`,`products`.`UOM_ID` AS `UOM_ID`,`products`.`Product_VAT` AS `Product_VAT`,`products`.`vat_percent` AS `vat_percent`,`products`.`vat2_percent` AS `vat2_percent`,`products`.`Status_ID` AS `Status_ID`,`products`.`Parent_ID` AS `Parent_ID`,`products`.`date_created` AS `date_created`,`products`.`created_logged_id` AS `created_logged_id`,`products`.`date_time` AS `date_time`,`products`.`Logged_ID` AS `Logged_ID`,`products`.`Product_Note` AS `Product_Note`,`products`.`product_description` AS `product_description`,`products`.`printer_id` AS `printer_id`,`products`.`Product_PLU` AS `Product_PLU`,`products`.`PLU_Type` AS `PLU_Type`,`products`.`Product_Arabic_Name` AS `Product_Arabic_Name`,`products`.`on_scale` AS `on_scale`,`products`.`product_type` AS `product_type`,`products`.`group_account_id` AS `group_account_id`,`products`.`Product_Limit_Discount` AS `Product_Limit_Discount`,`products`.`is_tax` AS `is_tax`,`products`.`product_color` AS `product_color`,`products`.`product_order` AS `product_order`,`products`.`row_number` AS `row_number`,`products`.`column_number` AS `column_number`,`products`.`page_number` AS `page_number`,`products`.`brand_id` AS `brand_id`,`products`.`section_id` AS `section_id`,`products`.`family_id` AS `family_id`,`products`.`machine_type_id` AS `machine_type_id`,`products`.`is_expiry` AS `is_expiry`,`products`.`link_note` AS `link_note`,`products`.`force_change_price` AS `force_change_price`,`products`.`duration_reservation` AS `duration_reservation`,`products`.`default_view_uom_id` AS `default_view_uom_id`,`products`.`default_view_rate` AS `default_view_rate`,`products`.`branch_id` AS `branch_id`,`products`.`is_lot` AS `is_lot`,`products`.`is_serial` AS `is_serial`,`products`.`main_supplier_id` AS `main_supplier_id`,`products`.`default_sales_uom` AS `default_sales_uom`,`products`.`default_purchase_uom` AS `default_purchase_uom`,`products`.`is_ticket` AS `is_ticket`,`products`.`is_service` AS `is_service`,`brands`.`brand_name` AS `brand_name`,`family`.`family_name` AS `family_name`,`cat`.`Cat_Name` AS `Cat_Name`,`products`.`positive_points` AS `positive_points`,`products`.`negative_points` AS `negative_points` from (((`tbl_stock_products` `products` left join `tbl_brand_products` `brands` on((`products`.`brand_id` = `brands`.`brand_id`))) left join `tbl_inventory_family` `family` on((`products`.`family_id` = `family`.`family_id`))) left join `tbl_product_cat` `cat` on((`products`.`Category_ID` = `cat`.`Cat_ID`)));
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'collect_points_pos', '0', 'bool', '0');
ALTER TABLE `tbl_customers` ADD `collected_points` INT NULL DEFAULT '0';
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'cleaning_collected_points', '0', 'bool', '0');
ALTER TABLE `tbl_customers` ADD `date_collected_point` DATE NULL;
ALTER TABLE `tbl_invoice_products_details` ADD `is_collected_points` INT NULL DEFAULT '0';
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'points_for_products', '0', 'bool', '0'), (NULL, 'collect_points_inv', '0', 'bool', '0');
ALTER VIEW `customer_list`  AS  select `c`.`Customer_ID` AS `ID`,`c`.`Customer_Code` AS `Customer_Code`,`c`.`Customer_Name` AS `Name`,`c`.`branch_id` AS `branch_id`,`c`.`Customer_Company` AS `Company`,`c`.`Customer_Mobile` AS `Customer_Mobile`,`c`.`Customer_Address` AS `Address`,`ca`.`Account_Code` AS `Account_Code`,`c`.`Status_ID` AS `Status_ID`,`sales`.`employee_id` AS `employee_id`,`org`.`branch_name` AS `branch_name`,0 AS `balance`,`c`.`collected_points` AS `collected_points`,`c`.`date_collected_point` AS `date_collected_point` from ((((`tbl_customers` `c` join `tbl_chart_of_accounts` `ca` on(((`ca`.`main_id` = `c`.`Customer_ID`) and (`ca`.`main_type` = 'cust') and (`ca`.`sub_type` = 'main')))) left join `tbl_common_currency` `cu` on((`c`.`Currency_ID` = `cu`.`Currency_ID`))) left join `tbl_salesman_customers` `sales` on((`c`.`Customer_ID` = `sales`.`customer_id`))) left join `tbl_organization_branches` `org` on((`c`.`branch_id` = `org`.`branch_id`)));
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'collected_points_for_customer', 'Collected Points For Customer', '41')
(by Aisha)

***************************************************************************
**************** 6/12/2023 update ****************
***************************************************************************
- add two inputs on the add product one for positive points and one for negative points (views/inventory/addproduct.php)
- add positive points and negative points to function[addProduct](libs/inventory/product.php)
- add two inputs on the edit product one for positive points and one for negative points (views/inventory/EditProduct.php)
- add positive points and negative points to function[updateProduct](libs/inventory/product.php)
- translate positive_points, negative_points (libs/common/commonLanguage.php)
- add positive points and negative points to edit multi product (views/inventory/edit_multi_product.php)
- add positive points and negative points to function[ProductBranchesAjax](controllers/inventoryAjax.php)
- add positive points and negative points to function[submitMultiProductEdit](libs/inventory/product.php)
- add collect point to pos (views/main_pos.php)
- add collect_points to system setting
- add setting_cleaning_collected_points to system setting
- translate collect_points, setting_collect_points_pos, setting_cleaning_collected_points (libs/common/commonLanguage.php)
- add customer_point_query to insert date_collected_point for customer function[createPOS](libs/inventory/invoicepos.php)
- add customer_points_query2, positive_points_query, positive_points and negative_points to add and decreases points to the collected_points for customer for customer function[createPOS](libs/inventory/invoicepos.php)
- add customer_point_query to insert date_collected_point for customer function[insertSalesInvoice](libs/inventory/invoice.php)
- add customer_points_query2, positive_points_query, positive_points and negative_points to add and decreases points to the collected_points for customer for customer function[insertSalesInvoice](libs/inventory/invoice.php)
- add column with checkbox is_collected_points to sales invoice (views/inventory/addpurchase.php)
- translate is_collected_points (libs/common/commonLanguage.php)
- add is_collected_points, is_collect_points_query and is_collect_points to check if is positive or negative points function[insertSalesInvoice](libs/inventory/invoice.php)
- add is_collected_points to function [editInvoice](libs/inventory/invoice.php)
- add is_collected_points to function [getInvoiceByID](libs/inventory/invoice.php)
- translate setting_points_for_products, setting_collect_points_inv (libs/common/commonLanguage.php)
- create collected points for customer (views/inventory/collected_points_for_customer.php)
- create function[collected_points_list](controllers/inventortyAjax.php)
- translate customer_phone, collected_points, collected_points_list, collected_points_for_customer (libs/common/commonLanguage.php)
- create function[empty_collected_points](controllers/inventory.php)(libs/inventory/product.php)(controllers/main_pos.php)
(by Aisha)

########################SQL######################SQL#######################
############## 22/1/2024 SQL update ##############
########################SQL######################SQL#######################
CREATE TABLE `apple_clinic`.`description_for_point` ( `id` INT NOT NULL AUTO_INCREMENT , `first_point` INT NULL DEFAULT NULL , `last_point` INT NULL DEFAULT NULL , `description` VARCHAR(255) NULL DEFAULT NULL , PRIMARY KEY (`id`));
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'description_for_points', 'Description For Points', '41');
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'add_description_for_points', 'Add Description For Points', '2094'), (NULL, 'edit_description_for_points', 'Edit Description For Points', '2094'), (NULL, 'delete_description_for_points', 'Delete Description For Points', '2094');
INSERT INTO `tbl_default_settings` (`setting_id`, `setting_name`, `setting_value`, `setting_type`, `is_private`) VALUES (NULL, 'enable_customer_points_page', '0', 'bool', '1');
(by Aisha)

***************************************************************************
**************** 22/1/2024 update ****************
***************************************************************************
- create description for points (views/inventory/description_for_points.php)
- translate Description_Points, from_point, to_point, description_for_points (libs/common/commonLanguage.php)
- add function[description_point_list](controllers/inventoryAjax.php)
- add function[add_descriptoin_points](controllers/inventoryAjax.php)(libs/inventory/product.php)
- add function[get_point_description](controllers/inventoryAjax.php)(libs/inventory/product.php)
- add function[delete_description_points](controllers/inventoryAjax.php)(libs/inventory/product.php)
- add function[update_description_points](controllers/inventoryAjax.php)(libs/inventory/product.php)
- create customer points page (views/customer_points_page.php)
- create customer points (controllers/customer_points_page.php)
- add open_customer_points_page to function[landing](controllers/smc.php)
- create function[open_customer_points_page](models/authModel.php)
- add customer_points_page (views/login.php)
- create function[get_customer_points_from_phone](libs/inventory/product.php)
- translate customer_phone, required_customer_phone_fields (libs/common/commonLanguage.php)

(by Aisha)

***************************************************************************
**************** 5/3/2024 update ****************
***************************************************************************
- make same number for invoice print and list in maintenance list change from maintenance_nb to maintenance_id in function[maintenance_list](controllers/ticketingAjax.php)

(by Aisha)
***************************************************************************
**************** 27/3/2024 update ****************
***************************************************************************
########################SQL######################SQL#######################
INSERT INTO `tbl_common_permission` (`Permission_ID`, `Permission_Name`, `Permission_Text`, `Parent_ID`) VALUES (NULL, 'sync_website', 'sync website', '1341');

ALTER TABLE `tbl_purchase_order` ADD `website_order_id` INT NULL  ;
ALTER TABLE `tbl_customers` ADD `customer_website_id` INT NULL  ;

########################SQL######################SQL#######################


- when send items with category and brand we must add brand with id 0 
- add permation for sync_website

########################SQL######################SQL#######################
######################## 25/9/2025 Update SQL#######################
########################SQL######################SQL#######################
CREATE VIEW `maintenance_list`  AS SELECT `maintenance`.`maintenance_id` AS `maintenance_id`, `maintenance`.`maintenance_nb` AS `maintenance_nb`, `maintenance`.`ime` AS `ime`, `maintenance`.`maintenance_note` AS `maintenance_note`, `maintenance`.`Employee_ID` AS `Employee_ID`, `maintenance`.`nonce` AS `nonce`, `maintenance`.`serial_number` AS `serial_number`, `maintenance`.`invoice_number` AS `invoice_number`, `maintenance`.`customer_id` AS `customer_id`, `maintenance`.`maintenance_type_id` AS `maintenance_type_id`, `maintenance`.`paid_amount` AS `paid_amount`, `maintenance`.`payment_account_id` AS `payment_account_id`, `maintenance`.`maintenance_date` AS `maintenance_date`, `maintenance`.`maintenance_status_id` AS `maintenance_status_id`, `maintenance`.`date_finished` AS `date_finished`, `maintenance`.`finished_by` AS `finished_by`, `maintenance`.`finished_solution` AS `finished_solution`, `maintenance`.`date_created` AS `date_created`, `maintenance`.`created_by` AS `created_by`, `maintenance`.`date_modified` AS `date_modified`, `maintenance`.`modified_by` AS `modified_by`, `maintenance`.`maintenance_reply_id` AS `maintenance_reply_id`, `cust`.`Customer_Name` AS `Customer_Name`, `maintenance_type`.`maintenance_type_name` AS `maintenance_type_name`, `stat`.`ticketing_status_name` AS `ticketing_status_name`, `maintenance`.`assigned_user_id` AS `assigned_user_id`, `maintenance`.`maintenance_schedule_date` AS `maintenance_schedule_date`, concat(`employee`.`Employee_FirstName`,' ',`employee`.`Employee_LastName`) AS `Employee_full_name`, `users`.`User_Name` AS `User_Name`, `maintenance`.`type_id` AS `type_id`, `brand`.`brand_name` AS `brand_name` FROM ((((((`tbl_maintenance` `maintenance` left join `tbl_customers` `cust` on(`cust`.`Customer_ID` = `maintenance`.`customer_id`)) left join `tbl_maintenance_type` `maintenance_type` on(`maintenance_type`.`maintenance_type_id` = `maintenance`.`maintenance_type_id`)) left join `tbl_hrm_employee` `employee` on(`employee`.`Employee_ID` = `maintenance`.`Employee_ID`)) left join `tbl_ticketing_status` `stat` on(`stat`.`ticketing_status_id` = `maintenance`.`maintenance_status_id`)) left join `tbl_common_users` `users` on(`users`.`User_ID` = `maintenance`.`assigned_user_id`)) left join `tbl_brand_products` `brand` on(`brand`.`brand_id` = `maintenance`.`type_id`)) ORDER BY `maintenance`.`maintenance_nb` DESC ;
(by Aisha)

***************************************************************************
**************** 25/9/2025 update ****************
***************************************************************************
- add type_id (views/ticketing/maintenance_list.php)
- add type_id to function[maintenance_list](controllers/ticketingAjax.php)
(by Aisha)

*/

define('MULTI_DB', '');  //user name and password for all dbs should be the same
define('invoice_dbs', '');  //Multi Invoice DB 
define('CUSTOM_FOLDER', '');  //name of the folder for the customization related to this project if there is
define('track_map_url', '');  //for app tracking map db
define('SMARTDINER_BRANCH_ID', '');    //smartdiner local branch id for sync. online
define('SMARTDINER_SYNC_URL', '');  //smartdiner sync upload product,.. online
define('SMART_DINER_URL', '');    //smartdiner get orders offline
//define('SMARTDINER_SYNC_URL', 'http://popeyeslebanon.com/admin/app');  //smartdiner sync upload product,.. online
//define('SMART_DINER_URL', 'http://popeyeslebanon.com/admin/');    //smartdiner get orders offline

/**
 * 
 */
if (!empty(smc_session()['default_setting']['default_time_zone'])) {
    date_default_timezone_set(smc_session()['default_setting']['default_time_zone']);
}else{
    date_default_timezone_set('Asia/Riyadh');
}
/**
 *  base directory
 */
define('ds', DIRECTORY_SEPARATOR);
define('ws', '/');
if (!defined('dirBase'))
    define('dirBase', dirname(__DIR__) . ds);
define('dirIncludes', dirBase . 'Includes' . ds);
//die(dirIncludes);

/**
 * Auto Path Detect
 */
$document_root = rtrim(filter_input(INPUT_SERVER, 'DOCUMENT_ROOT'), ds);
define('dirHost', str_replace(ws, ds, $document_root));
//define('dirHost',  $document_root);
$SITE_LINK = trim(str_replace(dirHost, '', dirBase), ds);
//define('SITE_LINK', 'http://' . $_SERVER['HTTP_HOST'] . ws . trim($SITE_LINK, ws) . ws);
define('SITE_LINK', (((!empty($_SERVER['SERVER_PROTOCOL']) && stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true) || (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || (!empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https')) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . ws . $SITE_LINK . ws);
/**
 * 
 */
define('APPLICATION', dirBase . 'Applicatipn/');
define('CONTROLLERS', dirBase . 'Controllers/');
define('MODELS', dirBase . 'Models/');
define('VIEWS', dirBase . 'Views/');
define('LIBS_PATH', dirBase . 'libs/');
define('LIBS_URL', SITE_LINK . 'libs/');
define('INC_PATH', dirBase . 'Includes/');

define('PUBLIC_PATH', 'Includes/Public/');
define('HTML', PUBLIC_PATH . 'HTML/');
define('THEME_PATH', 'Theme/');
define('VIEWS_PATH', 'Views/');
define('JS_PATH', THEME_PATH . 'js/');
define('CSS_PATH', THEME_PATH . 'css/');
define('FONTS_PATH', THEME_PATH . 'fonts/');
define('SIDEBAR_PATH', 'Includes/Public/HTML/Header/Sidebar/');
define('SYSTEM_PATH', dirBase);
//define('SCALE_PATH', 'D:\scale\kSolutions\DataGate');
define('appFiles', SITE_LINK . 'uploads/app_files/');
define('appFilesPath', dirBase . 'uploads/app_files/');
define('tmpAppFilesPath', dirBase . 'uploads/tmp_app_files/');
define('tmp_dir_path', dirBase . 'uploads/tmp/');
define('upload_path', dirBase . 'uploads/');
define('upload_url', SITE_LINK . 'uploads/');
//get the url
//change the db based on customer subdomain
//i.e.: trusto.plastrue.com a switch case will be generated to set its db
//we have to change the db_user, db_pass, db_name
//we should manage the switch case based on: $_SERVER['HTTP_HOST'];
//define('SITE_LINK', 'http://'.$_SERVER['HTTP_HOST'].'/');
define('TOOLTIP_SALES_ORDER', 'Define a new sales order for a defined customer with a defined pricing class');
define('TOOLTIP_SALES_ORDER_LIST', 'View All previous sales orders with the ability to edit each');
define('TOOLTIP_LOADING_ORDER', 'Assign Sales orders to a truck. Note: Sales order are linked to a zones, where you should select a truck within the same zone');
define('TOOLTIP_LOADING_ORDER_LIST', 'View all loading orders &#9474; Loading Validation &#9474; Return and Damage Amount &#9474; Payment of Loading Order');
define('TOOLTIP_NEW_ORDER_INVOICE', 'Create new invoice for a predefined sales order');
define('TOOLTIP_NEW_SALES_INVOICE', 'Create new invoice with or without customer for the additional loaded quantity');
define('TOOLTIP_CASH_RECEIVED', 'Enter the cash amount received from the driver, if the amount received from the driver is less than the total paid amount of the invoices deduction will be added to the driver');
