I finally completed the code for the salary calculation part. Could you please advise?
You can customize the wage calculation formula: for example
Pay-as-you-go = pay-as-you-go
Personal Income Tax = Tax (pay-as-you-go)
Create Table pq_unitgzxm (
Unit_id char (8) Not null default '',
Xmbh int not null default 0,
Xmmc varchar (200) not null default '',
GS varchar (400) not null default '',
GDX bit not null default '0 ',
BZ varchar (200) not null default '',
XTND bit not null default '0'
)
Go
Insert into pq_unitgzxm values ('20170901', 1, 'Basic sales', '', 1,'', 0 );
Insert into pq_unitgzxm values ('20140901', 2, 'bonus ', '', 1,'', 0 );
Insert into pq_unitgzxm values ('201312', 3, 'payroll payable ', '', 1,'', 0 );
Insert into pq_unitgzxm values ('20140901', 4, 'personal income tax ', '', 1, 'System-specific, unchangeable', 1 );
Insert into pq_unitgzxm values ('20140901', 5, 'payroll payable ', '', 1,'', 0 );
Insert into pq_unitgzxm values ('123456', 6, 'pay-as-you-go ', '', 1, 'System-specific, unchangeable', 1 );
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [pq_gzb] ')
And objectproperty (ID, N 'isusertable') = 1)
Drop table [pq_gzb]
Create Table pq_gzb (
Gzb_id char (8) Not null primary key,
Unit_id char (8) Not null default '',/* unit ID */
Dwmc varchar (400) not null default '',/* unit name */
Gzqjyear char (4) not null default '',/* Year of salary */
Gzqjperiod char (2) not null default '',/* salary period */
Gzffksrq varchar (10) Not null default '',/* Wage Payment start date */
Gzffjsrq varchar (10) Not null default '',/* pay end date */
Jsshebao varchar (2) not null default '',/* calculate social security */
Shebaoksrq varchar (10) Not null default '',/* Social Security start date */
Shebaojsrq varchar (10) Not null default '',/* Social Security end date */
FH varchar (8) Not null default '',/* compound */
FHR varchar (20) not null default ''/* Composite */
)
Go
Insert into pq_gzb (gzb_id, unit_id, dwmc, gzqjyear, gzqjperiod, gzffksrq, cosine, jsshebao, FH, FHR) values ('20140901', '2016', 'soft ', '123', '04 ', '2017-04-01', '2017-04-30 ', '1 ','','');
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [pq_gzmx] ')
And objectproperty (ID, N 'isusertable') = 1)
Drop table [pq_gzmx]
Create Table pq_gzmx (
Gzb_id char (8) Not null default '',
Employee_id char (8) Not null default '',
XM varchar (400) not null default '',
Dwmc varchar (400) not null default '',
Unitcontract_id char (8) Not null default '',
Employeecontract_id char (8) Not null default '',
Gzffksrq varchar (10) Not null default '',/* Wage Payment start date */
Gzffjsrq varchar (10) Not null default '',/* pay end date */
Yff varchar (8) Not null default '',/* Issued */
Gzdata1 decimal not null default '0 ',
Gzdata2 decimal not null default '0 ',
Gzdata3 decimal not null default '0 ',
Gzdata4 decimal not null default '0 ',
Gzdata5 decimal not null default '0 ',
Gzdata6 decimal not null default '0 ',
Gzdata7 decimal not null default '0 ',
Gzdata8 decimal not null default '0 ',
Gzdata9 decimal not null default '0 ',
Gzdata10 decimal not null default '0 ',
Gzdata11 decimal not null default '0 ',
Gzdata12 decimal not null default '0 ',
Gzdata13 decimal not null default '0 ',
Gzdata14 decimal not null default '0 ',
Gzdata15 decimal not null default '0 ',
Gzdata16 decimal not null default '0 ',
Gzdata17 decimal not null default '0 ',
Gzdata18 decimal not null default '0 ',
Gzdata19 decimal not null default '0 ',
Gzdata20 decimal not null default '0'
)
Go
Insert into pq_gzmx (gzb_id, employee_id, XM, dwmc, unitcontract_id, employeecontract_id, gzffksrq, values, gzdata1) values ('20140901', 'zhangsan', 'soft ', '1234568', '1997-04-01 ', '1997-04-30', 0 );
Insert into pq_gzmx (gzb_id, employee_id, XM, dwmc, unitcontract_id, employeecontract_id, gzffksrq, values, gzdata1) values ('20170901', '20170301', 'soft ', '1234568', '1997-04-01 ', '1997-04-30', 0 );
Function cal_salary ($ gzb_id = '', $ error = ''){
Global $ db, $ me, $ T, $ _ post;
Extract ($ _ post );
If ($ gzb_id &&! $ Error ){
$ Unit = $ db-> getrow ("select unit_id, dwmc from". tbl_gzb. "Where gzb_id = '$ gzb_id '");
$ Unit_id = $ Unit ['unit _ id'];
$ Dwmc = $ Unit ['dwmc '];
// Retrieve all salary items of the Unit
$ Unitgzxm = $ db-> getall ("select xmmc, GDX, gs from". tbl_unitgzxm. "Where unit_id = '$ unit_id '");
// Retrieve all payroll tables
$ Rs = $ db-> execute ("select * from". tbl_gzmx. "Where gzb_id = '$ gzb_id '");
While (! $ RS-> EOF) {// get a row of the payroll table and start processing and calculating this row
Debug_echo ("Now Cal the employee:". $ RS-> fields ['employee _ id']);
// Obtain a name-value pair of the current row, for example, $ data ['pay-as-you-go '] ['value'] => '000000' $ data ['pay-as-you-go'] ['value'] => '000000'
For ($ I = 0, $ COUNT = count ($ unitgzxm); $ I <$ count; $ I ++ ){
$ Data [$ unitgzxm [$ I] ['xmmc '] ['value'] = $ RS-> fields ['gzdata'. ($ I + 1)];
$ Data [$ unitgzxm [$ I] ['xmmc '] ['gs'] = $ unitgzxm [$ I] ['gs '];
If ($ unitgzxm [$ I] ['gdx'] = 1) {// It is fixed and used for calculation.
If (TRIM ($ unitgzxm [$ I] ['gs '])! = ""){
$ Data [$ unitgzxm [$ I] ['xmmc '] ['ready'] = 0; // indicates that the value has not been calculated.
} Else {
$ Data [$ unitgzxm [$ I] ['xmmc '] ['ready'] = 1; // fixed item, but the formula is empty. It is also considered ready.
}
} Else {
$ Data [$ unitgzxm [$ I] ['xmmc '] ['ready'] = 1; // indicates that the value is ready.
}
}
// Print_r ($ data );
$ Allcal = 0; // all calculated flags. If the value is 1, the computation is complete.
While ($ allcal = 0 ){
$ Havecontinue = 0;
For ($ I = 0, $ COUNT = count ($ unitgzxm); $ I <$ count; $ I ++ ){
If ($ data [$ unitgzxm [$ I] ['xmmc '] ['ready'] = 0) {// The value has not been calculated.
$ Allready = 1; // is all items in the formula ready?
// Retrieve all Chinese characters in the formula
Preg_match_all ("/[". CHR (0xa1 ). "-". CHR (0xff ). "] +/", $ data [$ unitgzxm [$ I] ['xmmc '] ['GS'], $ matches, preg_set_order );
// Check the ready status of each item
Foreach ($ matches as $ Val ){
If ($ data [$ Val [0] ['ready'] = 0 ){
$ Allready = 0;
}
Else {
$ Data [$ unitgzxm [$ I] ['xmmc '] ['gs'] = str_replace ($ Val [0], $ data [$ Val [0] ['value'], $ data [$ unitgzxm [$ I] ['xmmc '] ['gs']);
}
}
Debug_echo ("the Cal is". $ data [$ unitgzxm [$ I] ['xmmc '] ['GS']);
// If all items are ready, the calculation is complete. $ data [$ unitgzxm [$ I] ['xmmc '] ['ready'] = 1
// Otherwise, continue the for loop, check the next variable, and set the havecontinue flag
If ($ allready = 1 ){
// Replace the variable first
// Start Calculation
$ Expression = $ data [$ unitgzxm [$ I] ['xmmc '] ['GS'];
// $ Expression = "(2.33*6 )";
$ RPN = new math_rpn ();
$ Value = $ RPN-> calculate ($ expression, 'deg ', false );
Debug_echo ("the value is". $ value );
$ Record ["gzdata". ($ I + 1)] = $ value;
$ Data [$ unitgzxm [$ I] ['xmmc '] ['ready'] = 1;
} Else {
$ Havecontinue = 1;
Continue;
}
}
}
If (! $ Havecontinue) $ allcal = 1;
}
$ Db-> autoexecute (tbl_gzmx, $ record, 'update', "gzb_id = '$ gzb_id' and employee_id = '". $ RS-> fields ['employee _ id']. "'");
$ RS-> movenext ();
}
}
Show_form ($ gzb_id );
}
The custom functions with tax () added to the pear RPN package are as follows:
'Tax '=> array ('tax', 3, 1, '_ tax'), // hack by Daniel summer for rcpq
/**
* Tax Function
*
* @ Param array $ temp temporary Array
* @ Param integer $ POS position of operator
* @ Return float function's relult
* @ Access private
*/
Function _ tax ($ temp, $ POS ){
Global $ dB;
$ Value = $ temp [$ pos-1];
$ Base = $ db-> getone ("select * from". tbl_tax_base. "Where name = 'base '");
If ($ value <$ base) return 0 ;//
$ Value = $ value-$ base;
$ Rates = $ db-> getall ("select * from". tbl_tax_rate );
For ($ I = 0, $ COUNT = count ($ rates); $ I <$ count; $ I ++ ){
If ($ value >=$ rates [$ I] ['bottomline'] & $ value <= $ rates [$ I] ['topline']) {
$ Value = $ value * $ rates [$ I] ['rate'];
$ Value = $ value-$ rates [$ I] ['quickcal '];
Break;
}
}
Return $ value;
}