|
3 | 3 | // |
4 | 4 | package ru.petroglif.styloq; |
5 | 5 | import org.json.JSONArray; |
| 6 | +import org.json.JSONException; |
6 | 7 | import org.json.JSONObject; |
7 | 8 |
|
8 | 9 | import java.util.ArrayList; |
@@ -419,4 +420,246 @@ public boolean FromJson(JSONObject jsObj) |
419 | 420 | int Flags; |
420 | 421 | String Name; |
421 | 422 | } |
| 423 | + // |
| 424 | + // Descr: Структура, представляющая элемент списка долговых документов. |
| 425 | + // Используется для предоставления справки о долгах контрагента, в частности, в агентских заказах. |
| 426 | + // |
| 427 | + public static class DebtEntry { |
| 428 | + DebtEntry() |
| 429 | + { |
| 430 | + BillID = 0; |
| 431 | + BillDate = null; |
| 432 | + BillCode = null; |
| 433 | + AgentID = 0; |
| 434 | + Amount = 0.0; |
| 435 | + Debt = 0.0; |
| 436 | + } |
| 437 | + public boolean FromJson(JSONObject jsObj) |
| 438 | + { |
| 439 | + boolean ok = false; |
| 440 | + if(jsObj != null) { |
| 441 | + BillID = jsObj.optInt("billid", 0); |
| 442 | + { |
| 443 | + String date_text = jsObj.optString("billdate", null); |
| 444 | + if(SLib.GetLen(date_text) > 0) |
| 445 | + BillDate = SLib.strtodate(date_text, SLib.DATF_ISO8601); |
| 446 | + else |
| 447 | + BillDate = null; |
| 448 | + } |
| 449 | + BillCode = jsObj.optString("billcode", null); |
| 450 | + AgentID = jsObj.optInt("agentid", 0); |
| 451 | + Amount = jsObj.optDouble("amt", 0.0); |
| 452 | + Debt = jsObj.optDouble("debt", 0.0); |
| 453 | + ok = true; |
| 454 | + } |
| 455 | + return ok; |
| 456 | + } |
| 457 | + public JSONObject ToJsonObj() |
| 458 | + { |
| 459 | + JSONObject result = null; |
| 460 | + try { |
| 461 | + if(BillID > 0) { |
| 462 | + result = new JSONObject(); |
| 463 | + result.put("billid", BillID); |
| 464 | + if(BillDate != null) { |
| 465 | + String date_text = BillDate.Format(SLib.DATF_ISO8601|SLib.DATF_CENTURY); |
| 466 | + if(SLib.GetLen(date_text) > 0) |
| 467 | + result.put("billdate", date_text); |
| 468 | + } |
| 469 | + if(SLib.GetLen(BillCode) > 0) { |
| 470 | + result.put("billcode", BillCode); |
| 471 | + } |
| 472 | + if(AgentID > 0) |
| 473 | + result.put("agentid", AgentID); |
| 474 | + result.put("amt", Amount); |
| 475 | + result.put("debt", Debt); |
| 476 | + } |
| 477 | + } catch(JSONException exn) { |
| 478 | + result = null; |
| 479 | + } |
| 480 | + return result; |
| 481 | + } |
| 482 | + int BillID; |
| 483 | + SLib.LDATE BillDate; |
| 484 | + String BillCode; |
| 485 | + int AgentID; |
| 486 | + double Amount; |
| 487 | + double Debt; |
| 488 | + } |
| 489 | + // |
| 490 | + // Descr: Долговая выписка по одному контрагенту. |
| 491 | + // |
| 492 | + public static class ArDebtList { |
| 493 | + ArDebtList() |
| 494 | + { |
| 495 | + ArID = 0; |
| 496 | + ArName = null; |
| 497 | + SvcTime = null; |
| 498 | + CliTime = null; |
| 499 | + Debt = 0.0; |
| 500 | + List = null; |
| 501 | + } |
| 502 | + public boolean FromJson(JSONObject jsObj) |
| 503 | + { |
| 504 | + boolean ok = false; |
| 505 | + int items_count = 0; |
| 506 | + if(jsObj != null) { |
| 507 | + { |
| 508 | + String time_text = jsObj.optString("time", null); |
| 509 | + // SvcTime |
| 510 | + } |
| 511 | + ArID = jsObj.optInt("arid", 0); |
| 512 | + ArName = jsObj.optString("arname", null); |
| 513 | + items_count = jsObj.optInt("count", 0); |
| 514 | + Debt = jsObj.optDouble("debt", 0.0); |
| 515 | + JSONArray js_list = jsObj.optJSONArray("debt_list"); |
| 516 | + if(js_list != null && js_list.length() > 0) { |
| 517 | + List = new ArrayList<DebtEntry>(); |
| 518 | + for(int i = 0; i < js_list.length(); i++) { |
| 519 | + final JSONObject js_item = js_list.optJSONObject(i); |
| 520 | + if(js_item != null) { |
| 521 | + DebtEntry entry = new DebtEntry(); |
| 522 | + if(entry.FromJson(js_item)) |
| 523 | + List.add(entry); |
| 524 | + } |
| 525 | + } |
| 526 | + } |
| 527 | + else |
| 528 | + List = null; |
| 529 | + ok = true; |
| 530 | + } |
| 531 | + return ok; |
| 532 | + } |
| 533 | + public JSONObject ToJsonObj() |
| 534 | + { |
| 535 | + JSONObject result = null; |
| 536 | + final int items_count = SLib.GetCount(List); |
| 537 | + int real_items_count = 0; |
| 538 | + try { |
| 539 | + result = new JSONObject(); |
| 540 | + result.put("arid", ArID); |
| 541 | + if(SLib.GetLen(ArName) > 0) |
| 542 | + result.put("arname", ArName); |
| 543 | + if(SvcTime != null) { |
| 544 | + String dtm_text = SLib.datetimefmt(SvcTime, SLib.DATF_ISO8601 | SLib.DATF_CENTURY, 0); |
| 545 | + if(SLib.GetLen(dtm_text) > 0) |
| 546 | + result.put("time", dtm_text); |
| 547 | + } |
| 548 | + if(CliTime != null) { |
| 549 | + String dtm_text = SLib.datetimefmt(CliTime, SLib.DATF_ISO8601 | SLib.DATF_CENTURY, 0); |
| 550 | + if(SLib.GetLen(dtm_text) > 0) |
| 551 | + result.put("clitime", dtm_text); |
| 552 | + } |
| 553 | + result.put("count", items_count); |
| 554 | + result.put("debt", Debt); |
| 555 | + JSONArray js_list = new JSONArray(); |
| 556 | + for(int i = 0; i < items_count; i++) { |
| 557 | + final DebtEntry entry = List.get(i); |
| 558 | + if(entry != null) { |
| 559 | + JSONObject js_entry = entry.ToJsonObj(); |
| 560 | + if(js_entry != null) { |
| 561 | + js_list.put(js_entry); |
| 562 | + real_items_count++; |
| 563 | + } |
| 564 | + } |
| 565 | + } |
| 566 | + result.put("debt_list", js_list); |
| 567 | + } catch(JSONException exn) { |
| 568 | + result = null; |
| 569 | + } |
| 570 | + return result; |
| 571 | + } |
| 572 | + int ArID; |
| 573 | + String ArName; |
| 574 | + // Предусматриваем время сервиса и время клиента из-за того, что часы на них могут быть |
| 575 | + // рассинхронизированы. |
| 576 | + SLib.LDATETIME SvcTime; // Время формирования выписки сервисом |
| 577 | + SLib.LDATETIME CliTime; // Время получения выписки клиентом |
| 578 | + double Debt; // Итоговых долг по контрагенту |
| 579 | + ArrayList <DebtEntry> List; |
| 580 | + } |
| 581 | + // |
| 582 | + // Descr: Общий список долговых выписок по контрагентам. |
| 583 | + // Сохраняется в реестре StyloQ с типом документа StyloQDatabase.doctypDebtList |
| 584 | + // |
| 585 | + public static class DebtList { |
| 586 | + public static class ShortReplyEntry { |
| 587 | + ShortReplyEntry() |
| 588 | + { |
| 589 | + ArID = 0; |
| 590 | + Debt = 0.0; |
| 591 | + IsExpired = false; |
| 592 | + } |
| 593 | + int ArID; |
| 594 | + double Debt; |
| 595 | + boolean IsExpired; |
| 596 | + } |
| 597 | + DebtList() |
| 598 | + { |
| 599 | + List = null; |
| 600 | + } |
| 601 | + ShortReplyEntry GetDebt(int arID) |
| 602 | + { |
| 603 | + ShortReplyEntry result = null; |
| 604 | + if(arID > 0) { |
| 605 | + final int _c = SLib.GetCount(List); |
| 606 | + for(int i = 0; result == null && i < _c; i++) { |
| 607 | + final ArDebtList entry = List.get(i); |
| 608 | + if(entry != null && entry.ArID == arID) { |
| 609 | + result = new ShortReplyEntry(); |
| 610 | + result.ArID = entry.ArID; |
| 611 | + result.Debt = entry.Debt; |
| 612 | + result.IsExpired = false; // @todo |
| 613 | + } |
| 614 | + } |
| 615 | + } |
| 616 | + return result; |
| 617 | + } |
| 618 | + boolean FromJson(JSONObject jsObj) |
| 619 | + { |
| 620 | + boolean ok = false; |
| 621 | + List = null; |
| 622 | + if(jsObj != null) { |
| 623 | + try { |
| 624 | + JSONArray js_list = jsObj.optJSONArray("list"); |
| 625 | + if(js_list != null) { |
| 626 | + for(int i = 0; i < js_list.length(); i++) { |
| 627 | + ArDebtList entry = new ArDebtList(); |
| 628 | + if(entry.FromJson(js_list.getJSONObject(i))) { |
| 629 | + if(List == null) |
| 630 | + List = new ArrayList<ArDebtList>(); |
| 631 | + List.add(entry); |
| 632 | + ok = true; |
| 633 | + } |
| 634 | + } |
| 635 | + } |
| 636 | + } catch(JSONException exn) { |
| 637 | + ok = false; |
| 638 | + } |
| 639 | + } |
| 640 | + return ok; |
| 641 | + } |
| 642 | + JSONObject ToJsonObj() |
| 643 | + { |
| 644 | + JSONObject result = null; |
| 645 | + try { |
| 646 | + result = new JSONObject(); |
| 647 | + JSONArray js_list = new JSONArray(); |
| 648 | + final int _c = SLib.GetCount(List); |
| 649 | + for(int i = 0; i < _c; i++) { |
| 650 | + final ArDebtList entry = List.get(i); |
| 651 | + if(entry != null) { |
| 652 | + JSONObject js_entry = entry.ToJsonObj(); |
| 653 | + if(js_entry != null) |
| 654 | + js_list.put(js_entry); |
| 655 | + } |
| 656 | + } |
| 657 | + result.put("list", js_list); |
| 658 | + } catch(JSONException exn) { |
| 659 | + result = null; |
| 660 | + } |
| 661 | + return result; |
| 662 | + } |
| 663 | + ArrayList <ArDebtList> List; |
| 664 | + } |
422 | 665 | } |
0 commit comments