fix merge issues and rhai examples wip

This commit is contained in:
timurgordon
2025-05-22 23:57:33 +03:00
parent 93950bcab4
commit 0da512484f
28 changed files with 780 additions and 431 deletions

View File

@@ -14,14 +14,13 @@ print(`BusinessType Global: ${BusinessTypeConstants::Global}`);
// --- Testing Company Model ---
print("\n--- Testing Company Model ---");
let company1_id = 1001;
let company1_uuid = "comp-uuid-alpha-001";
let company1_name = "Innovatech Solutions Ltd.";
let company1_reg = "REG-ISL-2024";
let company1_inc_date = 1672531200; // Jan 1, 2023
print(`Creating a new company (ID: ${company1_id}, UUID: ${company1_uuid})...`);
let company1 = new_company(company1_id, company1_name, company1_reg, company1_inc_date)
print(`Creating a new company (UUID: ${company1_uuid})...`);
let company1 = new_company(company1_name, company1_reg, company1_inc_date)
.email("contact@innovatech.com")
.phone("+1-555-0100")
.website("https://innovatech.com")
@@ -38,26 +37,26 @@ print(`Company 1 Name: ${company1.name}, Status: ${company1.status}`);
print(`Company 1 Email: ${company1.email}, Industry: ${company1.industry}`);
// Save the company to the database
print("\nSaving company1 to database...");
set_company(company1);
company1 = set_company(company1); // Capture the company with the DB-assigned ID
print("Company1 saved.");
// Retrieve the company
print(`\nRetrieving company by ID (${company1_id})...`);
let retrieved_company = get_company_by_id(company1_id);
print(`\nRetrieving company by ID (${company1.id})...`);
let retrieved_company = get_company_by_id(company1.id);
print(`Retrieved Company: ${retrieved_company.name}, Status: ${retrieved_company.status}`);
print(`Retrieved Company Reg No: ${retrieved_company.registration_number}, Website: ${retrieved_company.website}`);
// --- Testing Shareholder Model ---
print("\n--- Testing Shareholder Model ---");
let sh1_id = 2001;
let sh1_user_id = 3001; // Example user ID
let sh1_name = "Alice Wonderland";
let sh1_since = 1672617600; // Example timestamp (Jan 2, 2023)
print(`Creating shareholder 1 (ID: ${sh1_id}) for company ${company1_id}...`);
let shareholder1 = new_shareholder(sh1_id)
.company_id(company1_id)
print(`Creating shareholder 1 for company ${company1.id}...`);
let shareholder1 = new_shareholder()
.company_id(company1.id)
.user_id(sh1_user_id)
.name(sh1_name)
.shares(1000.0)
@@ -66,20 +65,20 @@ let shareholder1 = new_shareholder(sh1_id)
.since(sh1_since)
.set_base_created_at(1672617600);
set_shareholder(shareholder1);
shareholder1 = set_shareholder(shareholder1);
print("Shareholder 1 saved.");
let retrieved_sh1 = get_shareholder_by_id(sh1_id);
let retrieved_sh1 = get_shareholder_by_id(shareholder1.id);
print(`Retrieved Shareholder 1: ${retrieved_sh1.name}, Type: ${retrieved_sh1.type_}, Shares: ${retrieved_sh1.shares}`);
let sh2_id = 2002;
let sh2_entity_id = 4001; // Example corporate entity ID
let sh2_name = "Mad Hatter Inc.";
let sh2_since = 1672704000; // Example timestamp (Jan 3, 2023)
print(`\nCreating shareholder 2 (ID: ${sh2_id}) for company ${company1_id}...`);
let shareholder2 = new_shareholder(sh2_id)
.company_id(company1_id)
print(`\nCreating shareholder 2 for company ${company1.id}...`);
let shareholder2 = new_shareholder()
.company_id(company1.id)
.user_id(sh2_entity_id) // Using user_id field for entity_id for simplicity in example
.name(sh2_name)
.shares(5000.0)
@@ -88,10 +87,10 @@ let shareholder2 = new_shareholder(sh2_id)
.since(sh2_since)
.set_base_created_at(1672704000);
set_shareholder(shareholder2);
shareholder2 = set_shareholder(shareholder2);
print("Shareholder 2 saved.");
let retrieved_sh2 = get_shareholder_by_id(sh2_id);
let retrieved_sh2 = get_shareholder_by_id(shareholder2.id);
print(`Retrieved Shareholder 2: ${retrieved_sh2.name}, Type: ${retrieved_sh2.type_}, Percentage: ${retrieved_sh2.percentage}`);
// --- Testing Update for Company (Example - if setters were fully implemented for complex updates) ---
@@ -105,7 +104,7 @@ print(`Updated Company - Name: ${updated_company.name}, New Phone: ${updated_com
set_company(updated_company);
print("Updated Company saved.");
let final_retrieved_company = get_company_by_id(company1_id);
let final_retrieved_company = get_company_by_id(company1.id);
print(`Final Retrieved Company - Description: '${final_retrieved_company.description}', Phone: ${final_retrieved_company.phone}`);
print("\n--- Testing Product Model ---");
@@ -127,12 +126,12 @@ let component1 = new_product_component("Super Capacitor")
print(`\nCreated Product Component: ${component1.name}, Qty: ${component1.quantity}`);
// Create Product 1 (a physical product with a component)
let product1_id = 3001;
let product1_name = "Advanced Gadget X";
let product1_creation_time = 1672876800; // Example timestamp (Jan 5, 2023)
print(`\nCreating Product 1 (ID: ${product1_id}): ${product1_name}...`);
let product1 = new_product(product1_id)
print(`\nCreating Product 1: ${product1_name}...`);
let product1 = new_product()
.name(product1_name)
.description("A revolutionary gadget with cutting-edge features.")
.price(299.99)
@@ -146,11 +145,11 @@ let product1 = new_product(product1_id)
.set_base_created_at(product1_creation_time);
print("Saving Product 1...");
set_product(product1);
product1 = set_product(product1);
print("Product 1 saved.");
print(`\nRetrieving Product 1 (ID: ${product1_id})...`);
let retrieved_product1 = get_product_by_id(product1_id);
print(`\nRetrieving Product 1 (ID: ${product1.id})...`);
let retrieved_product1 = get_product_by_id(product1.id);
print(`Retrieved Product 1: ${retrieved_product1.name}, Price: ${retrieved_product1.price}, Type: ${retrieved_product1.type_}`);
if retrieved_product1.components.len() > 0 {
print(`Product 1 Component 1: ${retrieved_product1.components[0].name}, Desc: ${retrieved_product1.components[0].description}`);
@@ -159,12 +158,12 @@ if retrieved_product1.components.len() > 0 {
}
// Create Product 2 (a service)
let product2_id = 3002;
let product2_name = "Cloud Backup Service - Pro Plan";
let product2_creation_time = 1672963200; // Example timestamp (Jan 6, 2023)
print(`\nCreating Product 2 (ID: ${product2_id}): ${product2_name}...`);
let product2 = new_product(product2_id)
print(`\nCreating Product 2: ${product2_name}...`);
let product2 = new_product()
.name(product2_name)
.description("Unlimited cloud backup with 24/7 support.")
.price(19.99) // Monthly price
@@ -175,11 +174,11 @@ let product2 = new_product(product2_id)
.set_base_created_at(product2_creation_time);
print("Saving Product 2...");
set_product(product2);
product2 = set_product(product2);
print("Product 2 saved.");
print(`\nRetrieving Product 2 (ID: ${product2_id})...`);
let retrieved_product2 = get_product_by_id(product2_id);
print(`\nRetrieving Product 2 (ID: ${product2.id})...`);
let retrieved_product2 = get_product_by_id(product2.id);
print(`Retrieved Product 2: ${retrieved_product2.name}, Category: ${retrieved_product2.category}, Status: ${retrieved_product2.status}`);
if retrieved_product2.components.len() > 0 {
print(`Product 2 has ${retrieved_product2.components.len()} components.`);
@@ -198,7 +197,7 @@ print(`Sale Status Completed: ${SaleStatusConstants::Completed}`);
print(`Sale Status Cancelled: ${SaleStatusConstants::Cancelled}`);
// Create SaleItem 1 (using product1 from above)
let sale_item1_product_id = product1_id; // Using product1_id from product example
let sale_item1_product_id = product1.id; // Using product1.id after it's set // Using product1_id from product example
let sale_item1_name = retrieved_product1.name; // Using name from retrieved product1
let sale_item1_qty = 2;
let sale_item1_unit_price = retrieved_product1.price;
@@ -209,7 +208,7 @@ let sale_item1 = new_sale_item(sale_item1_product_id, sale_item1_name, sale_item
print(`SaleItem 1: Product ID ${sale_item1.product_id}, Qty: ${sale_item1.quantity}, Subtotal: ${sale_item1.subtotal}`);
// Create SaleItem 2 (using product2 from above)
let sale_item2_product_id = product2_id; // Using product2_id from product example
let sale_item2_product_id = product2.id; // Using product2.id after it's set // Using product2_id from product example
let sale_item2_name = retrieved_product2.name;
let sale_item2_qty = 1;
let sale_item2_unit_price = retrieved_product2.price;
@@ -220,14 +219,13 @@ let sale_item2 = new_sale_item(sale_item2_product_id, sale_item2_name, sale_item
print(`SaleItem 2: Product ID ${sale_item2.product_id}, Qty: ${sale_item2.quantity}, Subtotal: ${sale_item2.subtotal}`);
// Create a Sale
let sale1_id = 4001;
let sale1_customer_id = company1_id; // Example: company1 is the customer
let sale1_customer_id = company1.id; // Example: company1 is the customer
let sale1_date = 1673049600; // Example timestamp (Jan 7, 2023)
let sale1_total_amount = sale_item1.subtotal + sale_item2.subtotal;
print(`\nCreating Sale 1 (ID: ${sale1_id}) for Customer ID: ${sale1_customer_id}...`);
print(`\nCreating Sale 1 for Customer ID: ${sale1_customer_id}...`);
let sale1 = new_sale(
sale1_id,
sale1_customer_id, // for company_id_i64 in Rhai registration
"Temp Buyer Name", // for buyer_name in Rhai registration
"temp@buyer.com", // for buyer_email in Rhai registration
@@ -262,12 +260,12 @@ print(`Sale 1 Base Comments: ${sale1.comments}`);
// Save Sale 1 to database
print("\nSaving Sale 1 to database...");
set_sale(sale1);
sale1 = set_sale(sale1);
print("Sale 1 saved.");
// Retrieve Sale 1 from database
print(`\nRetrieving Sale 1 by ID (${sale1_id})...`);
let retrieved_sale1 = get_sale_by_id(sale1_id);
print(`\nRetrieving Sale 1 by ID (${sale1.id})...`);
let retrieved_sale1 = get_sale_by_id(sale1.id);
print(`Retrieved Sale 1: ID ${retrieved_sale1.id}, Customer: ${retrieved_sale1.customer_id}, Status: ${retrieved_sale1.status}`);
print(`Retrieved Sale 1 Total: ${retrieved_sale1.total_amount}, Notes: '${retrieved_sale1.notes}'`);
if retrieved_sale1.items.len() > 0 {