What registers in 1C could look like in the presence of OOP

image






In 1C, registers are one of the key elements of the system. This term has its counterpart in the English language - ledger. It originally appeared in accounting practice, but over time, its logic began to be used in other areas.



Unlike 1C, where registers are one of the built-in types, there is no such concept in the lsFusion platform itself . But in it there is inheritance, polymorphism and aggregation, which, in particular, allows you to implement a similar register logic. In this article I will show how exactly by examples.



A register is a set of records, each of which reflects a state change for a certain set of subjects (or dimensions).



In 1C there are 4 types of registers:



  1. Accounting register
  2. Billing register
  3. Savings Register
  4. Information Register


The first two are highly specialized and are used only for accounting and payroll. Since lsFusion is a universal platform for developing business applications, I will not consider them, although it is quite simple to implement them. Let us dwell only on the last two types of registers.



Savings registers



Any entry in the register can be considered as an object of some abstract class. Suppose you want to implement a simple register that calculates the balance of a product in stock.



To do this, declare an abstract SkuLedger class:

CLASS ABSTRACT SkuLedger '   ';







, ( ).



Sku () Stock () . :

sku 'SKU' = ABSTRACT Sku (SkuLedger);

stock '' = ABSTRACT Stock (SkuLedger);







, :

dateTime '/' = ABSTRACT DATETIME (SkuLedger);







, , , 1 . , .

quantity '-' = ABSTRACT NUMERIC[14,2] (SkuLedger);







:

balance (Stock st, Sku sk) '' = GROUP SUM quantity(SkuLedger l) IF stock(l) = st AND sku(l) = sk;







, . , . , MATERIALIZED. , , 1.



, :

CONSTRAINT balance(Stock st, Sku sk) < 0 

    MESSAGE '       ';







, , . , , . , , 1 , , 1 .



, , :

balance (Stock st, Sku sk, INTEGER year) = 

    GROUP SUM quantity(SkuLedger l) IF stock(l) = st AND sku(l) = sk AND extractYear(dateTime(l)) = year MATERIALIZED;







. , , .



, :

balance '  ' (Stock st, Sku sk, DATETIME dt) = 

    GROUP SUM quantity(SkuLedger l) IF stock(l) = st AND sku(l) = sk AND dateTime(l) <= dt;







, . . , (MATERIALIZED), :

balance '  ' (Stock st, Sku sk, DATETIME dt) =

   currentBalance(sk, st) (-) (GROUP SUM quantity(SkuLedger l) IF stock(l) = st AND sku(l) = sk AND dateTime(l) > dt);







, , dateTime :

INDEX dateTime(SkuLedger l);







, .



, . :

CLASS Receipt '  ';

dateTime '/' = DATA DATETIME (Receipt);

stock '' = DATA Stock (Receipt);



CLASS ReceiptDetail '   ';

receipt '' = DATA Receipt (ReceiptDetail) NONULL DELETE;



sku 'SKU' = DATA SKU (ReceiptDetail);



quantity '-' = DATA NUMERIC[14,2] (ReceiptDetail);

price '' = DATA NUMERIC[14,2] (ReceiptDetail);







, . ReceiptDetail SkuLedger:

EXTEND CLASS ReceiptDetail : SkuLedger;







, , :

dateTime(ReceiptDetail d) += dateTime(receipt(d));



stock(ReceiptDetail d) += stock(receipt(d));



sku(ReceiptDetail d) += sku(d);

quantity(ReceiptDetail d) += quantity(d);







, .



, :



CLASS Transfer '    ';

posted '' = DATA BOOLEAN (Transfer);

dateTime '/' = DATA DATETIME (Transfer);



fromStock ' ()' = DATA Stock (Transfer);

toStock ' ()' = DATA Stock (Transfer);



CLASS TransferDetail '   ';

transfer '' = DATA Transfer (TransferDetail) NONULL DELETE;



sku 'SKU' = DATA SKU (TransferDetail);



quantity '-' = DATA NUMERIC[14,2] (TransferDetail);

price '' = DATA NUMERIC[14,2] (TransferDetail);







, . () , . , :

EXTEND CLASS TransferDetail : SkuLedger;



dateTime(TransferDetail d) += dateTime(transfer(d));



stock(TransferDetail d) += fromStock(transfer(d));



sku(TransferDetail d) += sku(d);

quantity(TransferDetail d) += -quantity(d);







, , .



, , , TransferSkuLedger, SkuLedger:

CLASS TransferSkuLedger '   ()' : SkuLedger;

transferSkuLedger = AGGR TransferSkuLedger WHERE stockTo(transfer(TransferDetail transferDetail));







AGGR , , , TransferSkuLedger, . .

:

dateTime(TransferSkuLedger d) += dateTime(transfer(transferDetail(d)));



stock(TransferSkuLedger d) += toStock(transfer(transferDetail(d)));



sku(TransferSkuLedger d) += sku(transferDetail(d));

quantity(TransferSkuLedger d) += quantity(transferDetail(d));







, , .



, 1 , :

, . , .


, , . , . , .





, , .



. :

CLASS ABSTRACT PriceLedger '   ';



dateTime '/' = ABSTRACT DATETIME (PriceLedger);



sku 'SKU' = ABSTRACT SKU (PriceLedger);

stock '' = ABSTRACT Stock (PriceLedger);



price '' = ABSTRACT NUMERIC[14,2] (PriceLedger);







:

price '' (Stock st, Sku sk, DATETIME dt) = 

    GROUP LAST price(PriceLedger l)

          ORDER dateTime(l), l

          WHERE dateTime(l) <= dt

          BY stock(l), sku(l);







, , . , , :

INDEX stock(PriceLedger l), sku(l), dateTime(l), l;







, , 1, lsFusion . , .



, :

EXTEND CLASS ReceiptDetail : PriceLedger;



dateTime(ReceiptDetail d) += dateTime(receipt(d));



stock(ReceiptDetail d) += stock(receipt(d));



sku(ReceiptDetail d) += sku(d);

price(ReceiptDetail d) += price(d);








1 , ( ). , 1 . , , , , (), .



lsFusion , . , , .



All Articles